在此的ListView无法点击,我想执行的项目点击的动作,但我不知道这是为什么无法点击,我还检查调试控制器还没有走在itemclicklistener,请大家帮帮忙谢谢
设计文件:
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
<复选框
机器人:ID =@ + ID / cbSolved
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
机器人:layout_marginLeft =15dp
机器人:layout_marginTop =20dp
机器人:文本=显示解决/>
<复选框
机器人:ID =@ + ID / cbMyCases
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignBaseline =@ + ID / cbSolved
机器人:layout_alignBottom =@ + ID / cbSolved
机器人:layout_alignParentRight =真
机器人:layout_marginRight =46dp
机器人:文本=我的案例/>
<的EditText
机器人:ID =@ + ID / etCaseSeacrh
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / cbSolved
机器人:layout_marginLeft =28dp
机器人:EMS =10
机器人:提示=搜索>
< /的EditText>
<的ListView
机器人:ID =@ + ID / liCases
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_above =@ + ID / btnNewCase
机器人:layout_alignParentLeft =真
机器人:layout_below =@ + ID / etCaseSeacrh
机器人:layout_marginTop =23dp
机器人:可点击=真正的>
< / ListView控件>
<按钮
机器人:ID =@ + ID / btnNewCase
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentBottom =真
机器人:layout_alignParentLeft =真
机器人:layout_alignParentRight =真
机器人:文本=新情况/>
< / RelativeLayout的>
这是我的Java类在此,我在访问列表中,但无法点击
公共类展示延伸活动{
ListView控件listshowcase;
EditText上搜索;
ListViewAdapter适配器;
@覆盖
保护无效的onCreate(包savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.screen4);
listshowcase =(ListView控件)findViewById(R.id.liCases);
适配器=新ListViewAdapter(本);
listshowcase.setAdapter(适配器);
listshowcase.setClickable(真正的);
listshowcase.setOnItemClickListener(新AdapterView.OnItemClickListener(){
@覆盖
公共无效onItemClick(适配器视图<>为arg0,视图中查看,INT ARG2,
长ARG3){
// TODO自动生成方法存根
字符串名称=((TextView中)view.findViewById(R.id.name))的getText()的toString()。
串成本=((TextView中)view.findViewById(R.id.email))的getText()的toString()。
字符串描述=((TextView中)view.findViewById(R.id.mobile))的getText()的toString()。
字符串ID =((TextView中)view.findViewById(R.id.id))的getText()的toString()。
//开始的新意图
意图=新的意图(getApplicationContext(),CompanyDetail.class);
in.putExtra(姓名,名);
in.putExtra(电子邮件,成本);
in.putExtra(FF,介绍);
in.putExtra(FFF,身份证);
startActivity(在);
}
});
搜索=(EditText上)findViewById(R.id.etCaseSeacrh);
search.addTextChangedListener(新TextWatcher(){
@覆盖
公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){
//调用回来当前字符的适配器过滤器
}
@覆盖
公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,之后INT){
}
@覆盖
公共无效afterTextChanged(编辑为arg0){
// TODO自动生成方法存根
}
});
}
这就是定制getview Listadapter类
@覆盖
公共查看getView(最终诠释paramInt,查看paramView,
最后的ViewGroup paramViewGroup){
// TODO自动生成方法存根
LayoutInflater充气= activity.getLayoutInflater();
如果(paramView == NULL){
鉴于=新ViewHolder();
paramView = inflator.inflate(R.layout.list_item,NULL);
view.name =(TextView中)paramView.findViewById(R.id.name);
view.email =(TextView中)paramView.findViewById(R.id.email);
view.mobile =(TextView中)paramView.findViewById(R.id.mobile);
view.id =(TextView中)paramView.findViewById(R.id.id);
paramView.setTag(视图);
} 其他 {
鉴于=(ViewHolder)paramView.getTag();
}
view.name.setText(TAG_NAME.get(paramInt));
view.email.setText(TAG_EMAIL.get(paramInt));
view.mobile.setText(TAG_PHONE_MOBILE.get(paramInt));
view.id.setText(TAG_ID.get(paramInt));
/*view.name.setFocusableInTouchMode(false);
view.name.setFocusable(假); * /
/*view.setOnClickListener(myClickListener);*/
view.name.setFocusable(假);
view.email.setFocusable(假);
view.mobile.setFocusable(假);
view.id.setFocusable(假);
返回paramView;
}
解决方案
好吧,你在那里有一个按钮。在您的list_item可XML认沽安卓:在LinearLayout中或RelativeLayout的descendantFocusability =blocksDescendants
您
In this ListVIew is not clickable, i want to perform an action on item click but i do not know why this is not clickable, i have also checked in debugging the controller is not gone in itemclicklistener, please help Thanks
design file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/cbSolved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="Show Solved" />
<CheckBox
android:id="@+id/cbMyCases"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cbSolved"
android:layout_alignBottom="@+id/cbSolved"
android:layout_alignParentRight="true"
android:layout_marginRight="46dp"
android:text="My Cases" />
<EditText
android:id="@+id/etCaseSeacrh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cbSolved"
android:layout_marginLeft="28dp"
android:ems="10"
android:hint="Search" >
</EditText>
<ListView
android:id="@+id/liCases"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnNewCase"
android:layout_alignParentLeft="true"
android:layout_below="@+id/etCaseSeacrh"
android:layout_marginTop="23dp"
android:clickable="true" >
</ListView>
<Button
android:id="@+id/btnNewCase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="New Case" />
</RelativeLayout>
This is my java class in this i am accessing list but is not clickable
public class ShowCases extends Activity{
ListView listshowcase;
EditText search;
ListViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.screen4);
listshowcase = (ListView) findViewById(R.id.liCases);
adapter = new ListViewAdapter(this);
listshowcase.setAdapter(adapter);
listshowcase.setClickable(true);
listshowcase.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
// TODO Auto-generated method stub
String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
String cost = ((TextView) view.findViewById(R.id.email)).getText().toString();
String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();
String id = ((TextView) view.findViewById(R.id.id)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), CompanyDetail.class);
in.putExtra("name", name);
in.putExtra("email", cost);
in.putExtra("ff", description);
in.putExtra("fff", id);
startActivity(in);
}
});
search=(EditText)findViewById(R.id.etCaseSeacrh);
search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Call back the Adapter with current character to Filter
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}
and this is getview of custom Listadapter class
@Override
public View getView(final int paramInt, View paramView,
final ViewGroup paramViewGroup) {
// TODO Auto-generated method stub
LayoutInflater inflator = activity.getLayoutInflater();
if (paramView == null) {
view = new ViewHolder();
paramView = inflator.inflate(R.layout.list_item, null);
view.name = (TextView) paramView.findViewById(R.id.name);
view.email = (TextView) paramView.findViewById(R.id.email);
view.mobile = (TextView) paramView.findViewById(R.id.mobile);
view.id = (TextView) paramView.findViewById(R.id.id);
paramView.setTag(view);
} else {
view = (ViewHolder) paramView.getTag();
}
view.name.setText(TAG_NAME.get(paramInt));
view.email.setText(TAG_EMAIL.get(paramInt));
view.mobile.setText(TAG_PHONE_MOBILE.get(paramInt));
view.id.setText(TAG_ID.get(paramInt));
/*view.name.setFocusableInTouchMode(false);
view.name.setFocusable(false);*/
/*view.setOnClickListener(myClickListener);*/
view.name.setFocusable(false);
view.email.setFocusable(false);
view.mobile.setFocusable(false);
view.id.setFocusable(false);
return paramView;
}
解决方案
Ok you have a button in there. In your list_item xml put android:descendantFocusability="blocksDescendants"
in the LinearLayout or RelativeLayout you have.