我正在尝试从另一个线程显示 ListView,但不确定我在这里缺少什么。这是 handleMessage() 方法,我也尝试创建一个计时器和 runOnUiThread() 方案,但这也无法显示任何内容。我确定列表视图本身没有问题,因为如果我再次调用整个活动,它将起作用(但是,不想使用该设计)。将不胜感激任何提示...
public void ShowList(String[] list)
{
for (String val : list)
Log.d(TAG, "ShowList: list = " +val);
// Set up the list view
GuideAdapter = new ArrayAdapter<String>(this, R.layout.main, android.R.id.list, list);
setListAdapter(GuideAdapter);
Log.d(TAG, "ShowList: Created setListAdapter...");
// Get an object for the list
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.setCacheColorHint(0);
listView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
}
});
}
Handler mHandler = new Handler(new Handler.Callback()
{
@Override
public boolean handleMessage(Message msg)
{
if (msg.what == STATE_GUIDE) {
ShowList(ChannelList);
}
return true;
}
});
public class MyThread extends Thread
{
public MyThread() {
}
public void run() {
...
mHandler.sendEmptyMessageDelayed(STATE_GUIDE, 0);
}
}