I have a page which contains a listview alone. Upon clicking a row in the list, the next page is loaded. This next page contains a set of buttons. Upon clicking a row in the list, the loading of the next page may take sometime. So if someone is continuously clicking the row then at some point of time, the second page comes and the buttons inside that gets clicked, which I dont require. How can I prevent this clicking of buttons? Can someone help me out. Thanks in advance.
Use AsyncTask concept to load data for next activity, do as follow:
set setEnabled(false) to all buttons inside the onPreExecute() method.
do all the background task inside the doInBackground() method.
and now again setEnabled(true) to all the buttons so that it become enabled and user can click on the buttons.
Besides the fact that your activities shouldn't take that long to load initially, you could just set a boolean when startActivity() is called to start the new activity. Then check that boolean if the user clicks anything else before the next activity is loaded.
if(document.readyState==complete) //NB this property is not supported by firefox
{
//Activate buttons
}
i think you need to false click event and true while you want to use
like this::
button1.setClickable(false);
and when you want to enable just write
button1.setClickable(true);
Related
I have a grid view when user presses a button i am changing grid view data and setting adapter again now on item click is not working but Touch listener is working WHY ?
I have two types of adapters when user presses button a i am setting first adapter when user presses button b i am setting second adapter data is changing but on item click not working?
Try to use AsyncTask (http://developer.android.com/reference/android/os/AsyncTask.html).
Because this kind of updates is always a problem, you have to do your adapter's update in onProgressUpdate or onPostExecute.
So, when your button is pressed, you execute your AsyncTask.
I know this is old, but maybe somebody else will seek for answers...
Anyway, I had a same issue and wasn't able to figure out why my onItemClick() didn't work. Instead of implementing onItemClick() inside your adapter, try doing it with adapter.setOnItemClickListener(). It worked for me ;)
I have an intent that loads a new activity, I also have some extra intent data to get when the new activity is started. Depending on what button is clicked on the first activity, it should scroll to a certain part of the scroll view on the next activity
It would be easiest to have it scroll down enough so that a certain item is at the top and the first thing read (defined by its ID)
Does anyone know how to do this?
Thanks
Check out the smoothScrollToPosition method in ListView:
http://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int)
This is what you can call to automatically show your list view to the desired position
ListView.setSelectionFromTop(index, 0);
to find out where to start you must compare the item that you want the list to show at startup from the list and the item that is received from your intent.
if you exactly know the position of a specific item in the listview you can call the method written above directly
I have a scenario where I want to programmatically change the value of my spinner using setSelection(). This works great, except that if the spinner is open (expanded?) an the time, the spinner does not close. Eg, the menu stays up, despite calling setSelection().
How can I programmatically close the spinner? I have tried performClick() to no avail.
edit: more details:
The reason I'm trying to do this is that my spinner actually uses a compound layout for each selection row. Namely, I have a linearlayout which contains an image, text, and button. The idea was that the button serves as an "edit" button (which opens an activity), while pressing on the image/text select the row (per usual).
The problem came when I added the button. Suddenly, the image & text no longer captured the press event to change the combo. In other words, adding a button to the row destroyed the touch-handling capacity of the entire row. So I tried to manually implement a click handler for the image/text, which subsequently executed a setSelection... which is where I ran into this problem.
You say that after adding the button you lost the click handle on the entire row. Try adding this android:descendantFocusability="blocksDescendants" to your row layout, and see if you can get the clicks to work properly.
Activity1 has a listView. Clicking one item (let's say item 3) will start Activity2. Activity2 have a back button once clicked will bring user back to Activity1. What I want to achieve is to highlight the item 3 when user back to Activity1 so that the user have a sense where to continue. (May be i need to set the focus to item 3 as well.)
EDIT: Following code works.
public void onResume()
{
super.onResume();
//lastSelectedPosition saved in OnItemClickListener
lv.setSelection(lastSelectedPosition);
lv.requestFocusFromTouch();
}
well its pretty simple. just save the clicked item position of the list to a field when the list is clicked to launch your new activity.
Afterwards in the onResume() method just use myList.setSelection(savedPosition);
as for the highlighting, well focus works kinda bad especially if you have a bit more complex rows(buttons,checkboxes etc) and other ui elements beside the list that can take away the focus. i believe the best way to achieve this is just set the background of that particullar item onResume to the highlighted one and override onScroll listener to just change the background to your default when the list is scrolled. indeed its a workaround but it will work in 100% of the cases opposite to just focusing an item. plus maybe you can add animations on the view so you can make it look really nice and smooth.
i have a image view and on top of it i have a button. now what i want is when i click on the button i should get a list of images on same Activity.actually i am trying to make a list in button,s onClick event. event gets fired but it does not show the list. anybody can have any idea how shall i achieve this i am also making my layout programmatically.
thanks alot
Without seeing some code it's hard to give a definite answer, but these are a few possibilities.
Create the listview together with the button, but set it's visibility to View.GONE or View.INVISIBLE. In the button's onClick method, set it to View.VISIBLE.
Alternatively, do the listview creation in the button's onClick (which I gather is what you're doing?), making sure you don't forget to add it to your layout. I have no idea why this does not work for you. Show some code or use the debugger to step through it and find out where it goes wrong.