I have a dynamic listview and I want to refresh the list when any new item is added.
How can I do this.Pls help me.
Thanks,
Monali
Call notifyDataSetChanged() on your adapter
Here is a demo for how u can do that http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
USE setListAdapter(yourAdapter);
Make your adapter to ListAdapter find more details here
then just use
yourAdapter.notifyDataSetChanged(); and you are done !
1) create a method
2) set adapterView in that method.
3) at click event of any image button call that method.
or to put Adapter.notifyDataSetChanged();
I think this would be easy for you.
Also you can do this like...
I have custom row for list. It has textview and I can change it's value ...
((TextView)(myWatchList.getChildAt(INDEX - myWatchList.getFirstVisiblePosition()).findViewById(R.id.symbolCountTV))).setText(NEWSTRING);
Related
Sorry for a brick of a code but I read that I need to run something on UI thread, how do I do that? private ArrayList JsonFIveDays(String weatherSearchResults) is where I set my listview adapter if that helps.
You have to notify the adapter whenever you do changes in the weatherArrayList.
For Example,
weatherAdapter.notifyDataSetChanged()
But in your case to use like that you have to declare the weatherAdapter as a property of the class.
I hope it will help you.
You need to notify adapter that you changed data with notifyDataSetChanged(). You can do that in setData method after changing data.
I have to get data from another Activity and set my text to those data in my onBindViewHolder, how can I do that, any ideas ?
When creating the adapter, send your Activity as context.
Then
adapter(Activity context);
..
context.getIntent();
..
I found this useful code of RecyclerView. Might it will help others. It is complete working example.
http://inducesmile.com/android/android-staggeredgridlayoutmanager-example-tutorial/
I have a ListView that I'm using for some different adapters, is this right to use following code for removing my ListView adapter and clear the ListView ?
list.setAdapter(new ArrayAdapter<Void>(mContext, 0, new Void[]{}));
What is your offer? and what is the best way?
Code has been updated
Simply Set Listview.setAdapter(null)
clear the data in the resource (i.e) what ever your using in the arrayAdapter
madapter.notifyDataSetChanged();
Is it possible to remove view or adapter from MergeAdapter somehow? I'd try to extend it and remove the view from pieces but it's private. Or maybe there's an alternative solution to show/hide view in this adapter? I tried to set its layout_height to zero and visibility to View.GONE, but it still shows the empty list item. Thanks in advance.
To remove a view or an adapter from MergeAdapter use the following methods:
setActive() on your mergeAdapter Instance.
For Example :
To remove a Textview (mytextView) from a MergeAdapter(merAdapter) use:
merAdapter.setActive(mytextViiew,false);
And to enable it again(to make it visible) use:
merAdapter.setActive(mytextViiew,true);
Refer the MergeAdapter documentation for details:
https://github.com/commonsguy/cwac-merge
Is it possible to remove view or adapter from MergeAdapter somehow?
Not presently, sorry. It shouldn't be too hard to add (remove it from the collection and call notifyDataSetChanged() to update the AdapterView) if you wanted to take a shot at it. Contributions are welcome! :-)
your MergeAdapter should be having method called getCount().. if i have understood you right, returning zero from there may solve your problem..
Expanding on Mark Murphy's answer, I think this is as simple as adding this method to MergeAdapter:
public void removeAdapter(ListAdapter la) {
pieces.remove(la);
}
remove() takes an object and will do all of the necessary testing & removal for you, if that object is contained in the pieces list. You could make this return a bool or something for your own purposes, but I had no such need.
Then just call something like:
int view_to_remove = *AN_INT*
adapter.removeAdapter(listAdapter.getAdapter(view_to_remove));
adapter.notifyDataSetChanged();
hello every one
i want to refresh my listview after adding or removing any data.. the adapter is from the SDcard how can i do this?
thanks in advance
call this code after your data are
change..
adapter.notifyDataSetChanged();
Use notifyDataSetChanged() of ArrayAdapter.
See the following code:
((EfficientAdapter)listView1.getAdapter()).notifyDataSetChanged();
Hope this will help you.