標籤:android color io ar 使用 sp 資料 on 問題
============問題描述============
代碼如下:
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);
程式中tempBus中的內容是有使用者更新的,我想在每次更新時只顯示更新後的內容,可當程式運行時每更新一次就會在ListVeiw中再加一次更新後的內容,未更新前的內容也顯示在ListView 上。請高手們幫幫忙,要怎樣在更新資料前把ListView中的內容清空?
============解決方案1============
tempBus更新是吧!你把上一次顯的tempBus[]清空不就行了!你那裡面的TextView要清除輕型?
============解決方案2============
作者應該用適配器來添加ListView的Item比較好吧
給你提供一個思路:
1,當我們要載入item的時候,首先把 list清空
list.clear();
適配器
adapter1 =new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter1);
這樣載入以後就把Listview 中的資料清空了
2,然後再載入我們想要的資料
list.add("a");
list.add("c");
list.add("b");
list.add("a");
list.add("c");
list.add("b");
適配器
adapter1 =new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter1);
adapter1 =new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter1);
這樣就可以清空以前的資料而得到我們更新的結果
如何清空android ListView控制項的內容