2010-05-15 67 views
0

後更新的細胞內視我ListViewActivityAndroid的列表式視圖。只是無效活動的看法

public class SelectActivity extends ListActivity { 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.select_one_of); 
     SimpleAdapter adapter = new SimpleAdapter(
      this, 
      createChildList(), 
      R.layout.select_one_of_childrow, 
      new String[] { KEY_VALUE }, 
      new int[] { R.id.selectoneof_add_new_item}); 
     setListAdapter(adapter); 
    } 
// ... 
} 

setListAdapter後()調用我想執行以下代碼:

((TextView) getListView().getChildAt(0).findViewById(R.id.selectoneof_add_new_item)).setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ticked, 0); 

但getListView()。 getChildAt(xxx)返回null,並捕獲NullPointerException。我應該在哪裏提到上面的代碼片段?

回答

1

我應該在哪裏提到上面 的代碼片段?

無處。相反,寫一個自定義ListAdapter並以這種方式自定義您的行。 Here is a free excerpt從我的書中演示了一般技術。

+0

我不相信這個!我仍然希望它可以簡單地完成,而無需編寫自己的/自定義ListAdapter – davs 2010-05-15 15:29:10

+0

恕我直言,「編寫自己的/自定義的ListAdapter」比您提議的更簡單也更可靠。 – CommonsWare 2010-05-15 18:13:24

+0

...但我不想在每個listView渲染過程中檢查...我需要在Activity的開始時執行一次操作... – davs 2010-05-15 20:07:59