国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

android中Lis-tView數據刷新時的同步方法

2019-11-02 14:54:57
字體:
來源:轉載
供稿:網友

   本文實例講述了android中ListView數據刷新時的同步方法。分享給大家供大家參考。具體實現方法如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 public class Main extends BaseActivity { private static final String TAG = "tag"; private static final int STATUS_CHANGE = 0; ExpandableListView mElv; ArrayList<GroupInfo> mGroupArray; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mElv = (ExpandableListView) findViewById(R.id.contact_list); mStatus = (TextView) findViewById(R.id.setStatus); mGroupArray = getIntent().getParcelableArrayListExtra("groupArray");// => 取數據 mExpandableAdapter = new ExpandableAdapter(this, Main.this); mElv.setAdapter(mExpandableAdapter); // 異步對比服務器分組和本地分組 HandlerThread handlerThread = new HandlerThread("handler_thread"); handlerThread.start(); UpdateGroupHandler myHandler = new UpdateGroupHandler( handlerThread.getLooper()); Message message = myHandler.obtainMessage(); message.sendToTarget(); mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case STATUS_CHANGE: // 處理UI更新等操作 updateUI(); break; } }; }; } /** * 發送消息更新UI */ private void sendMessageToUpdateUI() { Message msg = new Message(); msg.what = STATUS_CHANGE; mHandler.sendMessage(msg); // 向Handler發送消息,更新UI } private void updateUI() { // 詳細的更新 mExpandableAdapter.notifyDataSetChanged(); // 更新ExpandableListView } /** * 異步刷新分組的handler * * @author administrator * */ class UpdateGroupHandler extends Handler { public UpdateGroupHandler() { } public UpdateGroupHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { ContactsManagerDbAdapter dbAdapter = new ContactsManagerDbAdapter( Main.this); dbAdapter.open(); // =>doSomeThing... mGroupArray = groupList; System.out.println("========數據更新后,刷新listview========="); sendMessageToUpdateUI(); } } private class ExpandableAdapter extends BaseExpandableListAdapter { Activity activity; LayoutInflater layoutInflater; public ExpandableAdapter(Activity a, Context context) { activity = a; layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public Object getChild(int groupPosition, int childPosition) { return mGroupArray.get(groupPosition).getChildList() .get(childPosition); } public long getChildId(int groupPosition, int childPosition) { return childPosition; } public i
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建湖县| 汶川县| 新津县| 汽车| 集贤县| 阳城县| 孝义市| 嘉定区| 丰都县| 大英县| 莒南县| 龙游县| 竹北市| 伊宁县| 琼海市| 浦东新区| 西畴县| 屏山县| 阿拉善左旗| 民和| 大田县| 当阳市| 公主岭市| 翁源县| 昂仁县| 洛浦县| 平罗县| 山阴县| 临沧市| 崇义县| 卢湾区| 赤峰市| 共和县| 威信县| 桑植县| 湾仔区| 新源县| 宜州市| 达孜县| 当阳市| 东宁县|