static class MyHandler extends Handler {
WeakReference<MainActivity> wr;
public MyHandler(MainActivity mainActivity) {
wr = new WeakReference<MainActivity>(mainActivity);
}
@Override
public void handleMessage(Message msg) {
MainActivity mainActivity = wr.get();
switch (msg.what) {
case 0: {
Toast.makeText(mainActivity, (String) msg.obj,
Toast.LENGTH_LONG).show();
}
break;
case 1: {
String string = (String) msg.obj;
String[] strings = string.split("#");
try {
int a = Integer.parseInt(strings[0]);
if (a == (strings.length - 1)) {
for (int i = 1; i <= a; i++) {
String[] data = strings[i].split("\\|");
if (data.length == 2) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", data[0]);
map.put("name", data[1]);
mainActivity.lists.add(map);
}
}
}
SimpleAdapter simpleAdapter = new SimpleAdapter(
mainActivity, mainActivity.lists,
android.R.layout.simple_list_item_1,
new String[] { "name" },
new int[] { android.R.id.text1 });
mainActivity.listIDS.setAdapter(simpleAdapter);
simpleAdapter.notifyDataSetChanged();
mainActivity.listIDS
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
Message message = new Message();
message.what = 2;
message.obj = arg2;
handleMessage(message);
}
});
} catch (Exception e) {
}
}
break;
case 2: {
int a = (Integer) msg.obj;
mainActivity.GetState(a);
mainActivity.GetState();
/*mainActivity.timerTaskS;*/
}
break;
case 3: {
mainActivity.SetState((String) msg.obj);
mainActivity.handler.sendEmptyMessage(5);
}
break;
case 4: {
mainActivity.progressBar.setVisibility(ProgressBar.VISIBLE);
}
break;