我正在尝试在customdialog中创建一个列表视图。 listview包含一个包含4个textviews的自定义行。 我有点卡住,因为没有错误信息,但没有任何显示,适配器似乎是空的(但填充图有数据) - 我缺少什么?
protected Dialog onCreateDialog(int id) {
switch (id) {
case JOURNEY_DIALOG_ID:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.journey_dialog, (ViewGroup) findViewById(R.id.root));
AlertDialog.Builder journeyDialog = new AlertDialog.Builder(this);
journeyDialog.setView(layout);
// Configure the AlertDialog
journeyDialog.setTitle(myJourneyDetails.getString(JOURNEY_DETAILS_TITLE, "Journey"));
journeyDialog.setNegativeButton(R.string.go_back, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
JourneyResult.this.removeDialog(JOURNEY_DIALOG_ID);
onBackPressed();
}
});
journeyDialog.setMessage(journeyMessage);
String[] from = new String[] {"rowid", "segment length", "time1", "time2"};
int[] to = new int[] { R.id.textView_LVRowID, R.id.textView_LVSegmentLength, R.id.textView_LVTime1, R.id.textView_LVTime2 };
ListView timeList = (ListView) findViewById(R.id.listview_time_prediction);
// fill in the grid_item layout
try {
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.listview_row, from, to);
timeList.setAdapter(adapter);
adapter.notifyDataSetChanged();
timeList.invalidate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return journeyDialog.create();
}
return null;
}
感谢阅读
答案 0 :(得分:0)
如果customDialog中的ListView使用:
...
ListView timeList = (ListView) layout.findViewById(R.id.listview_time_prediction);
...
代替
...
ListView timeList = (ListView) findViewById(R.id.listview_time_prediction);
...