2013-03-06 97 views
1

我使用的Android清單片段,下面是我的適配器類如何將對象類型標籤設置爲列表視圖?

private class HugStatusAdapter extends ArrayAdapter<Status> { 
…………. 
public View getView(int position, View convertView, ViewGroup parent) { 

……….. 
//set tag to view(type Status is bean class) 
convertView.setTag(getItem(position)); 

} 
public void onListItemClick(ListView l, View v, int position, long id) { 
Bundle mBundle = new Bundle(); 
// how to get the tag (Status) and put it into mBundle 
} 
} 

我的問題是如何設置對象(狀態)類型的標籤進入視野,並從onListItemClick獲取標籤()?

回答

1

您已經將Status對象設置爲標記。你只需要稍後將它轉換回,即:

public void onListItemClick(ListView lv, View v, int pos, long id) { 
    Bundle mBundle = new Bundle(); 
    Status status = (Status)v.getTag(); 
    mBundle.putParcelable("status", status); 
} 

重要的是,對於上述工作,你Status必須實現Parcelable。有一個很好的例子here

相關問題