2012-03-21 45 views
1

我试图在customdialog中创建一个listview。 listview包含一个拥有4个textview的自定义行。 我有点卡住,因为没有错误消息,但没有显示和适配器似乎是空的(但fillmaps有数据) - 我错过了什么?simpleadapter似乎是空的 - 为什么?

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

如果内customDialog的ListView使用:

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

代替

... 
ListView timeList = (ListView) findViewById(R.id.listview_time_prediction); 
... 
+0

的感谢!我现在可以看到列表 - 不幸的是,并不是所有数据都在其中(看起来像我只是获得第一个textview),但现在正在修复布局:) – Sandra 2012-03-21 11:03:12

相关问题