0

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 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);
    }

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

after the change it blows up?
ERROR/AndroidRuntime(713): java.lang.ArrayIndexOutOfBoundsException
Check carefully the arguments (the length and postions) you pass to the method. And check the length of the two arrays you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.