也许有人可以告诉我为什么这不起作用以及为什么调用setListData后数组中的数据没有更新?
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);
}
答案 0 :(得分:2)
因为你把参数换成了
System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
如您所见,首先是来源,然后是目的地。
目前,您正在将array
的内容复制到本地临时array2
。