RSS订阅优然探索
你的位置:首页 » JAVA » 正文

java代理妙不可言

选择字号: 超大 标准 发布时间:2013-4-24 17:6:40 | 作者:admin | 0个评论 | 人浏览

 package com.lc.product.event;

 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.lc.basic.widget.LcNav.onButton1ClickListener;
import com.lc.product.R;
 
public class ListViewContactsAdapter extends BaseAdapter {
private Context context; // 运行上下文
private List<Map<String, Object>> listItems; // 商品信息集合
private LayoutInflater listContainer; // 视图容器
private boolean[] hasChecked; // 记录商品选中状态
int selectItem = -1;
 
public void setSelectItem(int selectItem) {
this.selectItem = selectItem;
}
 
public final class ListItemView { // 自定义控件集合
public ImageView image;
public TextView title;
public TextView info;
public CheckBox check;
public Button detail;
}
 
public final class ViewHolder {
public TextView typeView;
public TextView nameView;
public TextView timerView;
public TextView numberView;
public CheckBox nCheckBox;
}
 
public ListViewContactsAdapter(Context context,
List<Map<String, Object>> listItems) {
this.context = context;
listContainer = LayoutInflater.from(context); // 创建视图容器并设置上下文
this.listItems = listItems;
hasChecked = new boolean[getCount()];
 
isSelected = new HashMap<Integer, Boolean>();
for (int i = 0; i < listItems.size(); i++) {
isSelected.put(i, false);
}
}
 
public int getCount() {
// TODO Auto-generated method stub
return listItems.size();
}
 
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
 
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
 
public void setCheck(int position, boolean b) {
isSelected.put(position, b);
 
}
 
/**
* ListView Item设置
*/
public View getView(final int position, View convertView, ViewGroup parent) {
ListItemView listItemView = null;
ViewHolder holder = null;
// 获取list_item布局文件的视图
convertView = listContainer.inflate(R.layout.widget_contacts_listitem,
null);
holder = new ViewHolder();
holder.nameView = (TextView) convertView
.findViewById(R.id.contacts_listview_itemname);
holder.nameView.setText((String) listItems.get(position).get("title"));
 
holder.timerView = (TextView) convertView
.findViewById(R.id.contacts_listview_itemtel);
holder.timerView.setText((String) listItems.get(position).get(
"rightstring"));
 
holder.nCheckBox = (CheckBox) convertView
.findViewById(R.id.chkcontacts);
holder.nCheckBox
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
 
@Override
public void onCheckedChanged(CompoundButton arg0,
boolean isCheck) {
if (isCheck) {
isSelected.put(position, true);
} else if (!isCheck) {
isSelected.put(position, false);
}
if (onCheckBoxClickListener1 != null) {
onCheckBoxClickListener1.oncheckBoxclickListenr(position);
}
}
});
 
if (null != isSelected.get(position)) {
holder.nCheckBox.setChecked(isSelected.get(position));
}
 
convertView.setTag(holder);
return convertView;
}
 
public HashMap<Integer, Boolean> isSelected;
public void setonCheckBoxClickListener(onCheckBoxClickListener click) {
this.onCheckBoxClickListener1 = click;
}
private onCheckBoxClickListener onCheckBoxClickListener1;
public interface onCheckBoxClickListener {
public void oncheckBoxclickListenr(int position);
}
}

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。