2012-09-07 140 views
0

我有問題的列表視圖中的研究背景從FUNC改變創建自定義佈局(背景)

ListView控件通過JSON encdoe接收來自URL的數據一樣,/更新的ListView:

{"results":[ 
    {"db_id":"6","discount":"active","db_description":"bla bla bla ","db_num":"137","db_num2":"260"}, 
    {"db_id":"14","db_type":"discount","db_description":"blaaaaaaa","db_num":"39","db_num2":"46"}, 
    {"db_id":"18","db_type":"discount","db_description":"blaaaaaaa","db_num":"335","db_num2":"456"}, 
]} 

我的代碼:

   ListAdapter adapter = new SimpleAdapter(
         QueueActivity.this, QueueList, 
         R.layout.queue_row, new String[] { TAG_ID, TAG_DESCRIPTION, TAG_NUM, TAG_NUM2, TAG_IMAGE}, 
         new int[] { R.id.qid, R.id.description, R.id.num, R.id.num2, R.id.list_image }); 

       setListAdapter(adapter); 

onListItemClick我可以通過Simplay更新背景

protected void onListItemClick(ListView l, View v, int position, long id) { 
     super.onListItemClick(l, v, position, id); 
     v.setBackgroundResource(R.drawable.listview_taken_background); 
     TextView textid = (TextView) v.findViewById(R.id.queueid); 
     textid.setText("NEW TEXT") 
} 

但我需要更新從一個func的背景以及 我該怎麼做?

for ex,命令new FuncName()。execute(「2」);將用於第二排的底色資源設置爲「R.drawable.listview_taken_background」

回答

1

您可以使用ListView.getChildAt(int index)View在這個位置返回然後修改它的背景。

+0

查看listView = getListView()。getChildAt(0); listView.setBackgroundResource(R.drawable.listview_taken_background);我得到NullPointException – Kirma

+1

你確定在填充ListView後調用這個嗎? –

+0

是100%。該函數在setListAdapter(adapter)之後被調用; – Kirma