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 ;)
Related
I met a small problem.
My MainActivity has a Fragment which includes a ListView. There are some items showing on the ListView. After Clicking one item, another Activity will be opened. When I click the "UP" button and return to the MainActivity, everything is displayed properly except the ListView which is disappearing.
I realized that I needed to trigger the ListView repaint.
But so far, I only find one way:
listAdapter.clear();
listAdapter.addAll(...);
It was a little conter-intuitive because the content of the ListView wasn't changed and I just wanted to show them again.
So does anyone know any simple way to implement it?
Thanks!
You could invalidate it by doing
adapter.notifyDataSetChanged()
I have 2 different adapter for a ListView. Both adapters extends BaseAdapter.
I have 2 Button in the header view of the ListView.
Button 1 call ListView.setAdapter(adapter1);
Button 2 call ListView.setAdapter(adapter2);
The first time I click either one of the button. The ListView update to another adapter view immediately.
However, the second time I click either one of the button. The Button listener will not trigger until I scroll the ListView.
I have tried to put a toast inside the button listener. The toast is only called after I scroll the ListView.
Anyone have any idea what is the problem?
The UI in Android is efficient and will only update when it NEEDS to. In the case of your list the UI only updates when you scroll it because it needs to fetch more items for the list. To force an update you need to call invalidate() on your ListView.
I know Android execute 2 times (or sometimes even more) the getView() method of the adapter in order to draw the ListView correctly. I would like to know (or get notified) when it stops execute that method.
Why? The rows of my list are animated when user swipes on one of them. If the user swipes before Android has finished execute getView(), the animation is executed on the first row instead of the row touched by the user.
You can load ListView in background AsyncTask. And during that time you can show progress dialog on the screen so user is not able to do any action on your screen.
Check this Reference :
Load ListView in background AsyncTask
Hope this helps you.
Thanks.
There is no last getView()
When you are scrolling in a list, for each item that will become visible a getView() will be called. EVEN when it has already been on screen. I believe you are not detecting the list view item click properly.
When you touch some grid or listview items in an android app, he change the background color telling you that you have pressed it.
I'm having a problem in my app. When I create that a listview for instance, and I press it in my phone, he change color, but if I set the OnClick property, the item dont change it color. Whats wrong? The OnClick works as its suppose.
Thanks
Generally with ListView you want to use an OnItemClickListener.
This gives you a chance to perform an action based on the position in the list that was clicked.
If you need access to the view adapter from within onItemClick then you can use AdapterView#getAdapter() on the AdapterView that is supplied to you.
I have a ListActivity binding to a database with a Custom SimpleCursorAdapter.
in each of my list items I have 4 texts, image and checkbox (each one is set to focusable:false).
In the list itself I have a long button so when I press on it, I want it to delete all the
rows which thire checkboxes are 'checked'.
Now, I have tried many techniques in order to achieve a simple operation (click listeners, CheckedtextView as shown in the tutorial) but was not successful.
There is also another weird phenomenon occurring, after I #Override onListItemClick, also i dont get any calls at all while I am pressing on any of the list's rows.
Does anybody have any idea how to solve these issues? Thanks.
Thanks,
Moshic.
Are you calling super.onListItemClick(ListView, View, int, long);? if so, try write out a Log.d("ListView", "My list has been clicked"); and see if that comes out in the Logcat. If it doesn't, try extends ListActivity in your activity declaration. comment back if you want my help, I'll be ready to help as much as possible
create your own adapter with following features
-in getView() you have to set click listener for check box(it will be own listener for each check box)
-each element of adapter contains flag checked/unchecked, and you should set it by check box click listener from previous point
in activity with delete button click listener you have to get checked elements from adapter and do with them what you want
after then you should update list view for example by calling (your adapter).notifyDataSetChanged()