ListView项目在Android中不可点击 [英] ListView Item is not clickable in Android

查看:61
本文介绍了ListView项目在Android中不可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此ListView中不可单击,我想对项目单击执行一个操作,但我不知道为什么这不是不可单击的,我还检查了调试是否未在itemclicklistener中找到控制器.

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.

设计文件:

  <?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>

这是我正在访问列表中的java类,但无法单击

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

         }
    });
  }

这是自定义Listadapter类的getview

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;
 }

推荐答案

好的,您在那里有一个按钮.在您的list_item xml中,将android:descendantFocusability="blocksDescendants"放入您拥有的LinearLayout或RelativeLayout中.

Ok you have a button in there. In your list_item xml put android:descendantFocusability="blocksDescendants" in the LinearLayout or RelativeLayout you have.

这篇关于ListView项目在Android中不可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆