ListView、GridView更新顯示數據問題,我設置了一個按鈕,想點下按鈕就更新ListView顯示的數據,現在我這個代碼,點擊了按鈕之后,必須要滑動ListView才能將已顯示的內容改變。如何實現我點了按鈕之后就直接更改顯示的內容呢?以下是主要代碼,我自定義了一個MyAdapter類,繼承了BaseAdapter類,想要達到的效果如下兩圖所示:想要達到的效果是我點擊了改變ListView按鈕,就改變頁面所顯示的內容,希望大神能講講,困惑太久了,謝謝各位package com.example.baseadapterdemo;import java.util.ArrayList;import java.util.List;import android.os.Bundle;import android.os.Handler;import android.app.Activity;import android.view.Menu;import android.view.View;import android.widget.ListView;import com.example.bean.*;public class MainActivity extends Activity { private List<ItemBean> itemBeanList; private ListView listview; private MyAdapter myAdapter; private Handler handler;? ? @Override? ? protected void onCreate(Bundle savedInstanceState) {? ? ? ? super.onCreate(savedInstanceState);? ? ? ? setContentView(R.layout.activity_main);? ? ? ? listview = (ListView) findViewById(R.id.listview);? ? ? ? itemBeanList = new ArrayList<ItemBean>();? ? ? ? for(int i=0;i<10;i++){? ? ? ? itemBeanList.add(new ItemBean(? ? ? ? R.drawable.ic_launcher,? ? ? ? "標題" + i,? ? ? ? "內容:這是新聞頁面" + i? ? ? ? ));? ? ? ? }? ? ? ? myAdapter = new MyAdapter(this, itemBeanList);? ? ? ? listview.setAdapter(myAdapter);?? ? ? ??? ? ? ? handler = new Handler(){? ? ? ? public void handleMessage(android.os.Message msg) {? ? ? ? myAdapter = new MyAdapter(MainActivity.this, itemBeanList);? ? ? ? ? ? ? ? myAdapter.notifyDataSetChanged();? ? ? ? ? ? ? ? listview.setAdapter(myAdapter);?? ? ? ? ? ? ? ? listview.invalidate();? ? ? ? };? ? ? ? };? ? ? ??? ? } ?? ??? ? public void ChangeList(View v){? ? itemBeanList.clear();? ? ? ? for(int i=0;i<10;i++){? ? ? ? itemBeanList.add(new ItemBean(? ? ? ? R.drawable.ic_launcher,? ? ? ? "更新的標題" + i,? ? ? ? "內容:這是新聞頁面" + i? ? ? ? ));? ? ? ? } ??? ? ? ? new Thread(){? ? ? ? public void run() {? ? ? ? handler.sendEmptyMessage(1);? ? ? ? };? ? ? ? };? ? } ??}
添加回答
舉報
0/150
提交
取消
