2013-05-14 39 views
6

Trong ListView này không thể nhấp, tôi muốn thực hiện tác vụ khi nhấp vào mục nhưng tôi không biết tại sao điều này không thể nhấp được, tôi cũng đã kiểm tra gỡ lỗi bộ điều khiển không bị mất trong itemclicklistener .Mục ListView không thể nhấp được trong Android

tập Thiết kế:

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

Đây là lớp học java của tôi trong này tôi đang truy cập vào danh sách nhưng không thể nhấp

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 

     } 
    }); 
    } 

và đây là getview tùy chỉnh Listadapter lớp

@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; 
} 
+0

xóa tất cả tập hợpFocusable –

+0

sử dụng tính năng này, không hoạt động – Android

+0

có thể trùng lặp của [mục ListView không thể nhấp được. tại sao?] (http://stackoverflow.com/questions/8955270/listview-items-are-not-clickable-why) – rds

Trả lời

31

Ok bạn có một nút trong đó. Trong list_item xml của bạn, hãy đặt android:descendantFocusability="blocksDescendants" trong LinearLayout hoặc RelativeLayout mà bạn có.

+0

wow làm việc của nó, ay i knw những gì chức năng điều này ? – Android

+0

Tôi chấp nhận câu trả lời của bạn, xin vui lòng tôi muốn knw tính năng này, xin vui lòng cho biết nếu u có thể – Android

+1

Liên kết này http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several -clickable-areas/có rất nhiều thông tin hữu ích. Tôi sẽ không thể giải thích cũng như những gì được giải thích trong liên kết. –

0

Bạn có thể hiển thị danh sách không? Nếu có thì vui lòng hiển thị rằng layout giữ tệp TextView để hiển thị mục trong danh sách.

Thử xóa isTextSelectable khỏi số TextView trong trường hợp đó.

Kiểm tra nếu có một số sai lầm ngớ ngẩn như tôi đã thực hiện cách đây vài tháng từ đây:

onItemClick in ListView doesn't work

+0

sử dụng này, không hoạt động – Android

0

chỉ cần loại bỏ

listshowcase.setClickable(true); 

dòng này từ ShowCases. Và sau đó thử lại.

Tôi hy vọng điều này sẽ giúp bạn. Nếu không, vui lòng cho tôi biết.

+0

sử dụng này, không hoạt động – Android

0

thêm một OnClickListener cho mỗi lượt xem của bạn được trả lại từ bộ điều hợp của bạn.

Các vấn đề liên quan