调用notifyDataSetChanged后Listview更新不起作用。用户单击构建,我更新数据,但屏幕从未更新?有人可以告诉我为什么加载数据不起作用吗?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list1 = (ListView) findViewById(R.id.ListView01);
list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, array));
final EditText EditMessage = (EditText) findViewById(R.id.editTextWebSite);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String website = EditMessage.getText().toString();
//String returnString = loaddata(website);
Toast.makeText(v.getContext(),
"Updating Information",
Toast.LENGTH_LONG).show();
setListData();
BaseAdapter la = (BaseAdapter)list1.getAdapter();
((BaseAdapter) la).notifyDataSetChanged() ;
Toast.makeText(v.getContext(),
"Updated",
Toast.LENGTH_LONG).show();
}
});
private void setListData()
{
String array2[] = { "Iphone", "Tutorials", "Gallery", "Android", "item 1", "item 2", "item3", "item 4" };
System.arraycopy(array, 0, array2, 0, array.length);
}
最佳答案
尝试
((ArrayAdapter)list1.getAdapter()).notifyDataSetChanged() ;
而不是转换为 BaseAdapter。
关于java - 调用notifyDataSetChanged后 ListView 更新不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7405907/