Chunhao
Chunhao

Reputation: 170

java listview change Content

private String[] listView2 = {"aa","bb","cc","dd","ee"};

listView1 = (ListView)findViewById(R.id.listView1);
listAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,listView2);
listView1.setAdapter(listAdapter);

Change listView2[1] to "zzz".

Following code isn't work.

listView2[1] = "zzz";

Upvotes: 2

Views: 184

Answers (3)

Chunhao
Chunhao

Reputation: 170

Try this.^_^

public void newListView(){
    listAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,listView2);
    listView1.setAdapter(listAdapter);
}

listView2[0] = "zz";
newListView();

Upvotes: 0

Rustam
Rustam

Reputation: 6515

you can update adapter like this:

  adapter.insert("zz", 1);
  adapter.notifyDataSetChanged();

Upvotes: 0

Mattias Isegran Bergander
Mattias Isegran Bergander

Reputation: 11909

you also need to call

listAdapter.notifyDataSetChanged();

Or use one of the listAdpater methods for changing the data:

add(T), insert(T, int), remove(T), clear()

Upvotes: 1

Related Questions