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;
}
}
提示如下内容: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;
}
}
解决方案 »
- android4.0的View.setError()为什么不能显示文字了?
- 构造函数和onCreate()函数有什么区别?
- textView.setText(getChild(groupPosition,childPosition).toString());
- 那些年我们一起追过的android
- 请问什么时候用startservice和bindservice
- 模拟器信号问题
- Android实时通迅。
- openfire+spark+asmack(android平台);客户端频繁掉线问题,求解!!
- Android下如何同时开启wifi和移动网络
- android4.4.4源码编译报错
- android 连接sqlite 问题
- 求助:对ContenPRovider的数据库进行删除一条信息
其实在这个地方,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,就是无法弹出输入框。
v.requestFocus();
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);
这个现象很奇怪,
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);这样就能弹出输入键盘了,是不是和属性设置有关呢?