2013-03-06 91 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

相关问题