开发者

Array content isn't updated after System.arraycopy()

Maybe someone can tell me why this does not work and why the data in array is not updated after calling 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 Informati开发者_开发知识库on",
                        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);
    }


Because of you swapped the params for
System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length).

As you can see, it is first the source and then the destination.

Currently you are copying the content of array into the local temporary array2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜