Android : clear listview in Listadapter [duplicate] - android

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
how to clear my listview in android
In android, i have used a listadapter, simple adapter and passed an array and i want to clear the listview contents? Instead of clearing , it is appending the records to my listview.

Grab my Custom adapter from here. TestAdapter
Now add a method like this..
public void clearAdapter()
{
deviceNames.clear();
selected.clear();
notifyDataSetChanged();
}
Now call youListAdapter.clearAdapter() from you Activity.

Simply write listView.setAdapter(null)

Use notifydataSetInValidated() on your adapter to notify your listview that the data set is not longer valid. or set your addapter to null : l.setAdapter(null);

Related

Don't showing new record on ListView

i have 3 class. MainActivity,OneFragment,TwoFragment, I have listview which i fill using by Sqlite on OneFragment.And I add record from TwoFragment (with CreateData function using by my SqlHelper class) but new record dont showing in the listview.
How can i solve this?
If you want to see codes i can upload.
I highly recommend you to use RecyclerView instead of ListView (as Google says:
The RecyclerView widget is a more advanced and flexible version of ListView.
), but Both of them you need some refresh data may be like this on your OneFragment:
#Override
public void onResume() {
super.onResume();
items.clear();
items = dbHelper.getItems(); // reload the items from database
adapter.notifyDataSetChanged();
}
this question may help you with your problem Android ListView not refreshing after notifyDataSetChanged
if you do not understand send code

Retrieving data from parse.com and displaying in a table layout [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am able to retrieve the data, according to the logs, but not sure how to display them. I have created an activity with a table layout and tablerow with a textview to display the categories.
Logs:
If you just want to generate a prototype, you can use ParseQueryAdapter.
The code is from Parse.com docs
// Inside an Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Uses a layout with a ListView (id: "listview"), which uses our Adapter.
setContentView(R.layout.main);
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(this, "Instrument");
adapter.setTextKey("name");
adapter.setImageKey("photo");
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter;
}
https://parse.com/docs/android/guide#user-interface-parsequeryadapter
https://github.com/ParsePlatform/ParseUI-Android
You can custom your query by a queryFactory
https://parse.com/docs/android/guide#user-interface-customizing-the-query
Or you can custom your XXXAdapter(ListAdapter, ArrayAdapter, BaseAdapter).
Before call findInBG show a loading animation. Once done be called, set this list to your adapter, and then adapter.notifyDataSetChanged().
If you are just not familiar with using ListView, you should Google it.
As I see, this logs is JSON. May be the better way is use Gson deserialization.

Android, remove adapter from listview

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();

Android ArrayList Adapter does not change pictures [duplicate]

This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 8 years ago.
I have an ArrayList adapter wich used to load my listView.
My problem is that I want to change a pictures on the items in the list;
Until now I used a simple String array and didnt have any problem, but I had to change it to ArrayList wich loaded by an ORMlite selection and now my adapter doesent change the pictures...
I toast the text of the item wich is like ..."Asd"...
and in the adapter I use this:
if(textView.getText()=="Asd"){imageView.setImageResource(R.drawable.ic_asd);}
I also tried this:
if(values.get(position).getName()=="Asd")
{
imageView.setImageResource(R.drawable.ic_asd);
}
What is the problem? :S
Well, it's hard to say exactly what the issue is, but the main thing that's sticking out is that you're checking String equality wrong.
To check string equality, you should use Object.equals(Object obj); For example, textView.getText()=="Asd" should be textView.getText().toString().equals("Asd");
yes your problem is that you should use textview.getText().equals("Asd")
Use
if(textView.getText().toString().equals("Asd"))
I'm sure this is the problem ;)

How do I dynamically add items to a ListView in Android? [duplicate]

This question already has answers here:
How do you dynamically add elements to a ListView on Android?
(7 answers)
Closed 9 years ago.
I am using custom adapter to display a ListView.
It is working fine.
But i need to add three items to the ListView. How do I add them and have them display?
I tried notifydatasetchanged() method that is not working.
You have to add items to your list using list.add(...) then you tell the adapter with adapter.notifyDataSetChanged().
For adding item into the listview you must use the List/ArrayList object. Using this you can perform add/edit/delete operation on listview item data and this list set into your adapter to get the data from list/arraylist and set into list item.
Ok now suppose I have listview and want to add new item just add item into the list/arraylist object and notify to the adapter like this
List<String> myList = new ArrayList<String>();
ArrayAdapter<String> adapter;
oncreate(){
// initi listview, adapter and set the myList object into adapter object and then set the adapter into listview
}
// on button click from somewhere
public void onClick(View view){
myList.add("hello friends");// you can add your data here into list object
adapter.notifyDataSetChanged();
}

Categories

Resources