[英]I can't refresh my ArrayAdaper listview :S ¿how to do it?
我在 stackoverflow 上搜索了如何引用使用 ArrayAdapter 的列表視圖,我找到了一些解決方案,但是這些解決方案中的任何一個都不適合我!
我有一個帶有 NumberPicker 的界面和一個列表視圖。 當我按下數字選擇器的按鈕時,列表視圖必須自行更新,但不起作用。 當我按下按鈕時,列表視圖沒有更新自身,它保持相同的數據......但它必須更新,因為當您按下按鈕時,您正在更改適配器的一個參數並且適配器正在接收新數據。 ..
這是我的代碼:
public class Calendar extends Activity {
private ListView CalendarList = null;
private NumberPicker CalendarPicker = null;
private ArrayAdapter MyArrayAdapter = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar);
CalendarList = (ListView) findViewById(R.id.CalendarList);
CalendarPicker = (NumberPicker) findViewById(R.id.CalendarPicker);
CalendarPicker.setMaxValue(((MyApplication.NEQUIPOS*2)-2));//el maximo valor alcanzable por el picker es el numero de jornadas de la liga, es decir, ((NEQUIPOS*2)-2)
CalendarList.setClickable(false);
CalendarList.setFocusable(false);
CalendarList.setItemsCanFocus(false);
CalendarList.setSelected(false);
CalendarList.setEnabled(false);
CalendarPicker.increment.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
CalendarPicker.increment();
MyArrayAdapter.notifyDataSetChanged();
}
});
}
public void onResume() {
super.onResume();
CalendarPicker.setValue(MyApplication.RoundNumber);
MyArrayAdapter =new ArrayAdapter<String>(this, R.layout.list_item, MyApplication.roundMatches(CalendarPicker.getValue()));
MyArrayAdapter.setNotifyOnChange(true);
CalendarList.setAdapter(MyArrayAdapter);
}
}
在調用MyArrayAdapter.notifyDataSetChanged();
向適配器提供新數據,然后調用MyArrayAdapter.notifyDataSetChanged();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.