Wednesday, April 23, 2014

How empty the contents of android ListView control


Code is as follows:
BaseAdapter ba = new BaseAdapter ()
{

public int getCount () {
/ / TODO Auto-generated method stub
return count;
}

public Object getItem (int arg0) {
/ / TODO Auto-generated method stub
return null;
}

public long getItemId (int arg0) {
/ / TODO Auto-generated method stub
return 0;
}

public View getView (int arg0, View arg1, ViewGroup arg2) {
/ / TODO Auto-generated method stub
LinearLayout ll = new LinearLayout (ShowBusActivity.this);
ll.setOrientation (LinearLayout.HORIZONTAL);
TextView tv1 = new TextView (ShowBusActivity.this);
tv1.setText (routeID);
tv1.setTextSize (12);
tv1.setWidth (120);
tv1.setTextColor (Color.WHITE);
ll.addView (tv1);
TextView tv2 = new TextView (ShowBusActivity.this);
tv2.setText (tempBus [arg0] strCarId.);
tv2.setTextSize (12);
tv2.setWidth (120);
tv2.setTextColor (Color.WHITE);
ll.addView (tv2);
TextView tv3 = new TextView (ShowBusActivity.this);
tv3.setText (tempBus [arg0] distance.);
tv3.setTextSize (12);
tv3.setWidth (120);
tv3.setTextColor (Color.WHITE);
ll.addView (tv3);
TextView tv4 = new TextView (ShowBusActivity.this);
tv4.setText (tempBus [arg0] direction.);
tv4.setTextSize (12);
tv4.setWidth (120);
tv4.setTextColor (Color.WHITE);
ll.addView (tv4);
return ll;
}};

lv.setAdapter (ba);
The contents of the program are tempBus users to update, I think every time the display is updated only updated content can be updated when the program runs every once in ListVeiw will be coupled with a content update in the post, not updated content before it is displayed on the ListView. Please experts help, how to update data before emptying the contents of the ListView?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Someone?
Reply:
ListView.removeAllViews ();
Reply:
tempBus update is not it! You put on a display of tempBus [] emptied not on the list! You want to clear the inside TextView light?
Reply:
reference to the third floor of the reply:
tempBus update is not it! You put on a display of tempBus [] emptied not on the list! You want to clear the inside TextView light?

tempBus is a class array, which is stored in the class member variables to modify the class. I would like to display the contents of the ListView is cleared before the contents of the ListView.
Reply:
reference to the second floor of the reply:
ListView.removeAllViews ();

Add this function the error. Is there a function that can determine whether the ListView data.
Reply:
Authors should use the adapter to add a ListView Item relatively okay

To give you an idea:
1, when we want to load the item, first empty the list

list.clear ();

Adapter

adapter1 = new ArrayAdapter (getApplicationContext (), android.R.layout.simple_list_item_1, list);
listView.setAdapter (adapter1);

After this data is loaded to put the emptied
Listview
2, and then load the data we want

list.add ("a");
list.add ("c");
list.add ("b");
list.add ("a");
list.add ("c");
list.add ("b");

Adapter

adapter1 = new ArrayAdapter (getApplicationContext (), android.R.layout.simple_list_item_1, list);
listView.setAdapter (adapter1);
adapter1 = new ArrayAdapter (getApplicationContext (), android.R.layout.simple_list_item_1, list);
listView.setAdapter (adapter1);

So you can empty the previous data obtained by our updated results

Reply:
@ Flyinghoneybee thank the landlord and his friend, that bothers me three days to solve the problem
Mainly listview refresh problem, I have been unable to clear the previously added data, click again to add only based on the original, but also in other places before seen list.clear () this method, but it was considered to be self-righteous listview Without this method, only removeAllViews and clearFocus other methods, then see this post after Baidu under this method, just understand that list refers to a list <> collection, so in my program that I defined listData the
Forgive me so much nonsense, ha ha, novice white passing
Reply:
If the item replacement imageview it, each imageview pictures are the same, but also with arrayadapter? Is not the case, clear able to clean?
Reply:
The adapter.clear () can be friends

No comments:

Post a Comment