关闭

ListView刷新单个item

225人阅读 评论(0) 收藏 举报
分类:

public class ConstructionAdapter extends BaseAdapter {


private List<Construction> list;
private ConstructionRecordActivity activity;


public ConstructionAdapter(ConstructionRecordActivity activity,
List<Construction> list) {
this.activity = activity;
this.list = list;
}


@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}


@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}


@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = activity.getLayoutInflater().inflate(
R.layout.construction_list_item3, null, false);
viewHolder.tv_pile_no = (TextView) convertView
.findViewById(R.id.tv_pile_no);
viewHolder.tv_start_time = (TextView) convertView
.findViewById(R.id.tv_start_time);
viewHolder.tv_pile_length = (TextView) convertView
.findViewById(R.id.tv_pile_length);
viewHolder.tv_deviation = (TextView) convertView
.findViewById(R.id.tv_deviation);
viewHolder.tv_end_time = (TextView) convertView
.findViewById(R.id.tv_end_time);
viewHolder.tv_pile_time = (TextView) convertView
.findViewById(R.id.tv_pile_time);
viewHolder.tv_statues = (TextView) convertView
.findViewById(R.id.tv_statues);
viewHolder.tv_input_marker = (TextView) convertView
.findViewById(R.id.tv_input_marker);
viewHolder.iv_pile_finish = (ImageView) convertView
.findViewById(R.id.iv_pile_finish);
viewHolder.layout = (LinearLayout) convertView
.findViewById(R.id.layout);


convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final Construction data = list.get(position);
viewHolder.tv_pile_no.setText(data.getPile_no());
viewHolder.tv_start_time.setText(data.getStart_time());
viewHolder.tv_pile_length.setText(data.getPile_length() + "m");
viewHolder.tv_deviation.setText(data.getPile_deviation() + "mm");
viewHolder.tv_end_time.setText(data.getEnd_time());
viewHolder.tv_pile_time.setText(data.getPiling_time());
viewHolder.tv_input_marker.setText(data.getRemarks());
if (data.getStatues() == 2) {// 完成打桩
viewHolder.tv_statues.setText(activity
.getString(R.string.finish_piling));
viewHolder.iv_pile_finish.setImageResource((R.drawable.pile_finish));
} else {
// 中断打桩
viewHolder.tv_statues.setText(activity
.getString(R.string.interrupt_pile));
viewHolder.iv_pile_finish.setImageResource((R.drawable.interrupt_icon));
}
viewHolder.layout.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
activity.updatePileDialog(data.getRemarks(), data.getPile_no(),
position);
}
});
return convertView;
}


public static class ViewHolder {
TextView tv_pile_no;
TextView tv_start_time;
TextView tv_end_time;
TextView tv_pile_length;
TextView tv_deviation;
TextView tv_pile_time;
TextView tv_statues;
ImageView iv_pile_finish;
TextView tv_input_marker;
LinearLayout layout;
}


/**
* 更新单个item

* @param posi
* @param listView

* @param list

 * @param text,需要修改的内容

*/
public void updataView(int posi, PullToRefreshListview listView,
List<Construction> list, String text) {
int visibleFirstPosi = listView.getFirstVisiblePosition();
int visibleLastPosi = listView.getLastVisiblePosition();
if (posi >= visibleFirstPosi && posi <= visibleLastPosi) {
View view = listView.getChildAt(posi - visibleFirstPosi + 1);//这里我使用的是PullToRefreshListview要+1
if (view != null) {
ViewHolder holder = (ViewHolder) view.getTag();
Construction c = list.get(posi);
holder.tv_input_marker.setText(text);
c.setRemarks(text);//修改List对应的数据
}


}
}


}




activity中调用就可以了,都是项目代码

adapter.updataView(msg.arg1,listView,list,text);


1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:227次
    • 积分:13
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档
    阅读排行
    评论排行