java - System.arraycopy() 之后数组内容未更新

标签 java android arrays listview

也许有人可以告诉我为什么这不起作用以及为什么调用 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);
    }

最佳答案

因为你交换了参数
System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) .

如您所见,它首先是,然后是目的地

当前您正在将 array 的内容复制到本地临时 array2 中。

关于java - System.arraycopy() 之后数组内容未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7406483/

相关文章:

Java虚拟机多次崩溃

java - 在具有 AMD 处理器的计算机上运行 Android 模拟器

android - 如何在 Xamarin 的 visual studio 中定位 jdk?

javascript - 在 Angular 2 App 中使用 *ngIf 在负面情况下未获得预期结果

java - 如何获取第一个非空数组元素的索引?

java - Java 日期和时间 API 有什么问题?

java - 在jUnit测试中将参数传递给@Before设置

android - 房间数据库 : What is Index specific columns (indices and @Index) and how to use it?

android - imread在Android的OpenCV中不起作用

python - numpy的columnstack/hstack功能不一致