1

我正在尝试在自定义对话框中创建一个列表视图。listview 包含一个自定义行,其中包含 4 个文本视图。我有点卡住了,因为没有错误消息,但没有显示,适配器似乎是空的(但 fillmaps 有数据) - 我错过了什么?

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;
}

谢谢阅读

4

1 回答 1

0

如果 customDialog 中的 ListView 使用:

...  
ListView timeList = (ListView) layout.findViewById(R.id.listview_time_prediction);
...

反而

...  
ListView timeList = (ListView) findViewById(R.id.listview_time_prediction);
...
于 2012-03-21T10:49:30.237 回答