android 开发中 如何取得ListView 的 每条Item 的对象
首先写个ListView 的数据适配器,抽离出来,写一个对象,用来设置listView 每条Item 的 的对象,可以采用ConvertView 设置setTag 将View 房子tag中,可以通过ListvIEW .getChildAt().getTag. 取得你想要的对象,设置参数,还是铁代码吧!
getView:
ItemObj viewHolder = null;
if(convertView == null){
viewHolder = new ItemObj();
convertView = mLayoutInflate.inflate(R.layout.易做图_item, null);
viewHolder.mSimpleCardName = (TextView) convertView.findViewById(R.id.易做图_name);
viewHolder.mIsReTake = (TextView) convertView.findViewById(R.id.易做图_num);
viewHolder.mContentNext = (TextView)convertView.findViewById(R.id.status);
viewHolder.mIsNext = (TextView) convertView.findViewById(R.id.icon_next);
convertView.setTag(viewHolder);
}else{
viewHolder = (ItemObj) convertView.getTag();
}
PhotoList aPotoLists = (PhotoList) getItem(position);
if(aPotoLists!= null){
viewHolder.mSimpleCardName.setText(aPotoLists.photoName);
if(KeyInMapITF.TAKESIMPLE_PIC_TEP!= null){
viewHolder.mIsReTake.setText("("+0+")");
if(KeyInMapITF.TAKESIMPLE_PIC_TEP.equals(aPotoLists.photoName)){
ArrayList<PhotoList> aLists= (ArrayList<PhotoList>) GlobalParameter.get(KeyInMapITF.TAKESIMPLE_PIC_TEP);
viewHolder.mIsReTake.setText("("+aLists.size()+")");
}
}
if(aPotoLists.status.equals("0")){
viewHolder.mContentNext.setText("未审核");
viewHolder.mIsNext.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.task_list_arrows));
}else{
viewHolder.mContentNext.setText("已审核");
viewHolder.mIsNext.setText("");
convertView.setOnClickListener(null);
}
}
obj 对象:
public class ItemObj extends Object{
public TextView mSimpleCardName;// 单证的名称
public TextView mIsReTake;// 0 是 单证拍照 1是重拍照片
public TextView mContentNext;// 未提交 未审核等
public TextView mIsNext;// 箭头
public TextView getmSimpleCardName() {
return mSimpleCardName;
}
public void setmSimpleCardName(TextView mSimpleCardName) {
this.mSimpleCardName = mSimpleCardName;
}
public TextView getmIsReTake() {
return mIsReTake;
}
public void setmIsReTake(TextView mIsReTake) {
this.mIsReTake = mIsReTake;
}
public TextView getmContentNext() {
return mContentNext;
}
public void setmContentNext(TextView mContentNext) {
this.mContentNext = mContentNext;
}
public TextView getmIsNext() {
return mIsNext;
}
public void setmIsNext(TextView mIsNext) {
this.mIsNext = mIsNext;
}
补充:移动开发 , Android ,