-1

私はこれが原因で立ち往生しています....すべての問題(私が思う)はそれです。

それに応じてアクティビティのリストビューonCreateメソッドとsetAdapterを設定したため、一度だけ作成されたアクティビティとしてLISTVIEWを更新できません。

誰かが正しい答えを見つけたら、私を案内してください..お願いします

4

1 に答える 1

0

You can call notifyDataSetChanged() on the Adapter of your ListView, or set a new Adapter for your ListView somewhere else in code.

Please also have a look at this post for specific information:

Android: how to refresh ListView contents?

Taken from the post above:

// this could be inside your oncreate method:
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(defaultAdapter);  // the defaultAdapter is the ListAdapter you first added to the listview, its a member-variable

// this will refresh the adapter and therefore refresh the listView
public void refreshListViewContent() {

    List<Item> newItems = getNewListViewItems(); // get the new listview items from somewhere

    defaultAdapter.clear();  // clear your adapter
    defaultAdapter.addAll(newItems); // add the new items
    defaultAdapter.notifyDataSetChanged();  // do the actual refresh
}

The method refreshListViewContent() can be called from anywhere in your code, for example when you click a Button or something like that:

Button button = (Button) findViewById(R.id.btn1);
button.setOnClickListener(new View.OnClickListener() {

       public void onClick(View v) {

           refreshListViewContent();
       }
 });
于 2013-08-16T15:35:12.567 に答える