我无法刷新我的 ArrayAdaper 列表视图:S ¿怎么办?
我在 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);
}
}
i searched on stackoverflow for how to refres a listview that uses ArrayAdapter, and i find some solutions, but any of these solutions didn't work for me!
i have a interface with a NumberPicker, and a listview. When i press on the buttons of the numberpickers, the listview must update itself, but didn't works. When i press the buttons the listview didn't update itselft, it stay with the same data... but it have to update because when you press a button, you are changing one parameter of the adapter and the adapter is receiving new data...
this is my code:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用
MyArrayAdapter.notifyDataSetChanged();
向适配器提供新数据,然后调用MyArrayAdapter.notifyDataSetChanged();
之前Before you call
MyArrayAdapter.notifyDataSetChanged();
feed the adapter with the new data and then callMyArrayAdapter.notifyDataSetChanged();