android listview里有checkbox 和edittext,希望checkbox 被选中时edittext可用,未选中时不可用。结果无法弹出输入框。
提示如下内容:05-30 09:16:21.820: W/TextView(15726): TextView does not support text selection. Action mode cancelled.
希望各位大侠帮忙看下!代码如下package com.android.food;import java.util.List;
import java.util.Map;import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
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.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class Adpter extends BaseAdapter{
private List<Map<String, Object>> data;
private LayoutInflater mylayoutInflater=null;
 public Adpter(Context context, List<Map<String, Object>> datafrom){             
         data =  datafrom;
         this.mylayoutInflater = LayoutInflater.from(context);  } 
 public class ViewHolder{         
public TextView number;         
public TextView name;         
public TextView danwei;         
public RadioGroup radioGroup;
public EditText many;
public CheckBox radio0;
public RadioButton radio1;
public RadioButton radio2;
public RadioButton radio3;
public RadioButton radio4;
public RadioButton radio5;
public RadioButton radio6;
public RadioButton radio7;
public RadioButton radio8;
public RadioButton radio9;
public RadioButton radio10;

}  @Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return data.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
 final ViewHolder holder = new ViewHolder(); 
 //Log.i("data", data.get(position).toString());
 //if(convertView==null){
convertView = mylayoutInflater.inflate(R.layout.grain, null);
   
holder.number = (TextView) convertView.findViewById(R.id.number);
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.danwei = (TextView) convertView.findViewById(R.id.danwei);
holder.many = (EditText) convertView.findViewById(R.id.many);
holder.radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup1);
holder.radio0 = (CheckBox) convertView.findViewById(R.id.radio0);
holder.radio1 = (RadioButton) convertView.findViewById(R.id.radio1);
holder.radio2 = (RadioButton) convertView.findViewById(R.id.radio2);
holder.radio3 = (RadioButton) convertView.findViewById(R.id.radio3);
holder.radio4 = (RadioButton) convertView.findViewById(R.id.radio4);
holder.radio5 = (RadioButton) convertView.findViewById(R.id.radio5);
holder.radio6 = (RadioButton) convertView.findViewById(R.id.radio6);
holder.radio7 = (RadioButton) convertView.findViewById(R.id.radio7);
holder.radio8 = (RadioButton) convertView.findViewById(R.id.radio8);
holder.radio9 = (RadioButton) convertView.findViewById(R.id.radio9);
holder.radio10 = (RadioButton) convertView.findViewById(R.id.radio10);
convertView.setTag(holder); 
 holder.radio0.setChecked((Boolean) data.get(position).get("eat"));
 holder.number.setText(data.get(position).get("number").toString());
 holder.name.setText((String)data.get(position).get("name"));
 holder.danwei.setText((String)data.get(position).get("danwei"));
 holder.many.setText((String)data.get(position).get("many").toString());
 holder.many.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("data", "i am clicked");
Log.i("data", "holder.many.isFocusable="+holder.many.isFocusable());
Log.i("data", "holder.many.isEnabled="+holder.many.isEnabled());

}
});
 
 final RadioButton[] radio = {
 holder.radio1,holder.radio2,holder.radio3,
 holder.radio4,holder.radio5,holder.radio6,
 holder.radio7,holder.radio8,holder.radio9,
 holder.radio10,
       };
 holder.radio0.setOnCheckedChangeListener(new OnCheckedChangeListener(){ @Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
data.get(position).put("eat", isChecked);
if(!isChecked){
 holder.radioGroup.setEnabled(false);
 holder.radioGroup.setFocusable(false);
 holder.radioGroup.clearCheck();
 for (RadioButton radionew : radio) {
 radionew.setEnabled(false);
 radionew.setFocusable(false);
}
 holder.many.setFocusable(false);
 holder.many.setEnabled(false);
 holder.many.setText("0");
 
 }
 else{
 holder.many.setFocusable(true);
 holder.many.setEnabled(true);
 holder.many.setText("0");
 
 holder.radioGroup.setEnabled(true);
 holder.radioGroup.setFocusable(true);
 for (RadioButton radionew : radio) {
 radionew.setEnabled(true);
 radionew.setFocusable(true);
}
 
 }
}
 
 });
 if(!holder.radio0.isChecked()){
 holder.radioGroup.setEnabled(false);
 holder.radioGroup.clearCheck();
 for (RadioButton radionew : radio) {
 radionew.setEnabled(false);
 radionew.setFocusable(false);
}
 holder.many.setFocusable(false);
 holder.many.setEnabled(false);
 holder.many.setText("0");
 }
 
 
 if((Integer) data.get(position).get("checkid")!=0){
 holder.radioGroup.check((Integer) data.get(position).get("checkid"));
 }


 holder.many.addTextChangedListener(new TextWatcher(){ @Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub

} @Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

} @Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
data.get(position).put("many", s);
}
 
 });
 
 holder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
data.get(position).put("checkid", checkedId);
 int i=0;
for (RadioButton radionew : radio) {
i++;
if(radionew.isChecked()){
data.get(position).put("time", i);
}
}
}
 
 }); return convertView;
}

}

解决方案 »

  1.   

    checkbox 会遮挡住 listview item的click 和focusable 属性, 用户点击时只能响应checkbox ,而listview中对应的item无法获得 click 事件, 建议不要用checkbox
      

  2.   

    谢谢各位的建议,我头一次发帖,O(∩_∩)O~以后会改进的!
    其实在这个地方,checkbox的监听器:
    holder.radio0.setOnCheckedChangeListener(new OnCheckedChangeListener(){            @Override
                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                    // TODO Auto-generated method stub
                    data.get(position).put("eat", isChecked);
                    if(!isChecked){
                         holder.radioGroup.setEnabled(false);
                         holder.radioGroup.setFocusable(false);
                         holder.radioGroup.clearCheck();
                         for (RadioButton radionew : radio) {
                             radionew.setEnabled(false);
                             radionew.setFocusable(false);
                            }
                         holder.many.setFocusable(false);
                         holder.many.setEnabled(false);
                         holder.many.setText("0");
                         
                     }
                     else{
                         holder.many.setFocusable(true);
                         holder.many.setEnabled(true);
                         holder.many.setText("0");
                         
                         holder.radioGroup.setEnabled(true);
                         holder.radioGroup.setFocusable(true);
                         for (RadioButton radionew : radio) {
                             radionew.setEnabled(true);
                             radionew.setFocusable(true);
                            }
                         
                     }
                }
                 
             });
    editText已经做出了响应,而且当checkbox选中的时候,edittext的监听事件也可作出反应:
    holder.many.setOnClickListener(new View.OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Log.i("data", "i am clicked");
                    Log.i("data", "holder.many.isFocusable="+holder.many.isFocusable());
                    Log.i("data", "holder.many.isEnabled="+holder.many.isEnabled());
                    
                }
            });
    也可打印出信息 isFocusable isEnabled均为true,就是无法弹出输入框。
      

  3.   

    就是点击 EditText 不弹出输入文字的键盘  出不来 
      

  4.   

    在Log.i("data", "i am clicked");前面加上
    v.requestFocus();
     
      

  5.   

    1. 检查你的manifest看看是不是设置了不弹出 input method 的属性。
    2. you can try this when user click edit text.InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(mMessageEditField, InputMethodManager.HIDE_NOT_ALWAYS);
      

  6.   

    你好 O(∩_∩)O谢谢回复!
    这个现象很奇怪,
    1、就是点击Edittext是会提示TextView does not support text selection. Action mode cancelled.
    2、就是isFocusable isEnabled均为true,弹不出键盘。但是重新调用getview键盘就能弹出来了
    3、我把
    holder.many.setFocusable(false);
    holder.many.setEnabled(false);
    改为holder.many.setVisibility(View.INVISIBLE);
    holder.many.setFocusable(true);
    holder.many.setEnabled(true);
    改为holder.many.setVisibility(View.VISIBLE);这样就能弹出输入键盘了,是不是和属性设置有关呢?
      

  7.   

    setFocusable是设置能否获得焦点,setEnabled是设置是否可用,都是和能弹出输入键盘有直接关系的。
      

  8.   

    不能弹出是焦点问题。同样的,如果在listview中有button那么焦点也会优先被button获得,那么editText就得不到焦点,弹不出编辑框,难道这样你在listview中button也不用了?我就在listView中用过CheckBox,也有editText,解决方法非常简单,一句代码,设置editText获得焦点即可,listview中对应的item也是有办法获得click事件的,因为有点小问题就叫别人不要用。。这太蛋疼了吧。
      

  9.   

    不能弹出是焦点问题。同样的,如果在listview中有button那么焦点也会优先被button获得,那么editText就得不到焦点,弹不出编辑框,难道这样你在listview中button也不用了?我就在listView中用过CheckBox,也有editText,解决方法非常简单,一句代码,设置editText获得焦点即可,listview中对应的item也是有办法获得click事件的,因为有点小问题就叫别人不要用。。这太蛋疼了吧。
      

  10.   

    不能弹出是焦点问题。同样的,如果在listview中有button那么焦点也会优先被button获得,那么editText就得不到焦点,弹不出编辑框,难道这样你在listview中button也不用了?我就在listView中用过CheckBox,也有editText,解决方法非常简单,一句代码,设置editText获得焦点即可,listview中对应的item也是有办法获得click事件的,因为有点小问题就叫别人不要用。。这太蛋疼了吧。
      

  11.   

    这listview数据是动态的吗?接下来还能获取edittext输入的内容吗?