在我的ExpandableListview
中,我使用的Imageview
和Checkbox
类似于形状图像和名称,
当我勾选特定子项的checkbox
时,在滚动选中的状态更改后,另一个子项也会被勾选,
我需要选择多个值。
请帮我解决这个问题
提前致谢。
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
_childText = (String) getChild(groupPosition, childPosition);
int itemType = getChildType(groupPosition,childPosition);
Log.e("childPosition", "karjeevch "+childPosition);
ViewHolder viewHolder = null;
switch (itemType) {
case 0:
viewHolder = null;
if (convertView==null) {
viewHolder=new ViewHolder();
convertView = infalInflater.inflate(R.layout.list_child_shape, null);
viewHolder.shape_name = (CheckBox) convertView.findViewById(R.id.shape_chk_box);
viewHolder.img_shape_icon=(ImageView)convertView.findViewById(R.id.img_shape);
imageLoader.DisplayImage("http://rosycontact.com/shashvat/images/"+_childText+".png", viewHolder.img_shape_icon);
viewHolder.shape_name.setText(_childText);
convertView.setTag(viewHolder);
final CheckBox shape_name_temp=viewHolder.shape_name;
viewHolder.shape_name.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if (shape_name_temp.isChecked()==true) {
All_link.SHAPE=shape_name_temp.getText().toString();
}
}
});
//new PerformBackgroungTask().execute();
}
else{
viewHolder=(ViewHolder)convertView.getTag();
}
return convertView;
//break;
case 1:
viewHolder = null;
if (convertView==null) {
viewHolder=new ViewHolder();
convertView = infalInflater.inflate(R.layout.list_child_carat, null);
viewHolder.carat_from = (TextView) convertView.findViewById(R.id.ed_carat_from);
viewHolder.carat_to = (TextView) convertView.findViewById(R.id.ed_carat_to);
viewHolder.carat_from.setText("jdsv");
viewHolder.carat_to.setText("jdsv");
All_link.CARAT_FROM=viewHolder.carat_from.getText().toString();
All_link.CARAT_TO=viewHolder.carat_to.getText().toString();
}
else{
viewHolder=(ViewHolder)convertView.getTag();
}
return convertView;
case 2:
viewHolder = null;
if (convertView==null) {
viewHolder=new ViewHolder();
convertView = infalInflater.inflate(R.layout.list_child_color, null);
viewHolder.color_from = (Spinner) convertView.findViewById(R.id.spn_color_from);
viewHolder.color_to = (Spinner) convertView.findViewById(R.id.spn_color_to);
ArrayAdapter adapter = new ArrayAdapter(_context, android.R.layout.simple_spinner_item, SearchActivity.color_list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
viewHolder.color_from.setAdapter(adapter);
viewHolder.color_to.setAdapter(adapter);
convertView.setTag(viewHolder);
final Spinner color_from_temp=viewHolder.color_from;
final Spinner color_to_temp=viewHolder.color_to;
// Changing textcolor
viewHolder.color_from.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
All_link.COLOR_FROM=color_from_temp.getSelectedItem().toString();
((TextView) parent.getChildAt(0)).setTextColor(Color.parseColor("#003974"));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
viewHolder.color_to.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
All_link.COLOR_TO=color_to_temp.getSelectedItem().toString();
((TextView) parent.getChildAt(0)).setTextColor(Color.parseColor("#003974"));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
else{
viewHolder=(ViewHolder)convertView.getTag();
}
return convertView;
答案 0 :(得分:0)
试试这个:
case 0:
viewHolder = null;
if (convertView==null) {
viewHolder=new ViewHolder();
convertView = infalInflater.inflate(R.layout.list_child_shape, null);
viewHolder.shape_name = (CheckBox) convertView.findViewById(R.id.shape_chk_box);
viewHolder.img_shape_icon=(ImageView)convertView.findViewById(R.id.img_shape);
imageLoader.DisplayImage("http://rosycontact.com/shashvat/images/"+_childText+".png", viewHolder.img_shape_icon);
viewHolder.shape_name.setText(_childText);
convertView.setTag(viewHolder);
//final CheckBox shape_name_temp=viewHolder.shape_name;
viewHolder.shape_name.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
All_link.SHAPE=shape_name_temp.getText().toString();
}
}
});
//new PerformBackgroungTask().execute();
}
else{
viewHolder=(ViewHolder)convertView.getTag();
}
return convertView;
//break;