android中怎么获取listview的item的信息
1个回答
2015-04-13 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517190
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
首先写个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.simple_item, null);
viewHolder.mSimpleCardName = (TextView) convertView.findViewById(R.id.simple_name);
viewHolder.mIsReTake = (TextView) convertView.findViewById(R.id.simple_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;
}
getView:
ItemObj viewHolder = null;
if(convertView == null){
viewHolder = new ItemObj();
convertView = mLayoutInflate.inflate(R.layout.simple_item, null);
viewHolder.mSimpleCardName = (TextView) convertView.findViewById(R.id.simple_name);
viewHolder.mIsReTake = (TextView) convertView.findViewById(R.id.simple_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;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询