2013-04-20 7 views
8

मुझे एक अजीब समस्या का सामना करना पड़ रहा है, मैंने अपनी सूची दृश्य में एक कस्टम पंक्ति जोड़ा है जब मैं बटन पंक्ति को हटा रहा हूं चुनिंदा है, लेकिन जैसा कि मैं बटन जोड़ता हूं, मैं क्लिक करने में सक्षम नहीं हूं पंक्ति, कृपया नीचे एक्सएमएल देखें।बटन के साथ एंड्रॉइड लिस्ट व्यू चुनने योग्य नहीं है (क्लिक करने योग्य)

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

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="77dp" 
    android:layout_height="77dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="18dp" 
    android:src="@drawable/company_logo" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="Idds sdsad " 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/imageView1" 

    android:layout_below="@+id/textView1" 
    android:textColor="#8b8989" 
    android:layout_marginLeft="5dp" 
    android:text="Tap to see detail" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView2" 
    android:layout_centerHorizontal="true" 
    android:text="Button" /> 

मदद कृपया यह क्यों हो रहा है।

उत्तर

18

कोशिश एक्सएमएल में अपने Button को

android:focusable="false" 
android:focusableInTouchMode="false" 

की स्थापना। Button पंक्ति पर ध्यान केंद्रित करें, यही कारण है कि आप अपनी पंक्ति का चयन नहीं कर सकते हैं।

26

जैसा कि आप अपनी कस्टम पंक्ति का उपयोग कर रहे हैं।

onclickListenerbutton के लिए button के लिए focusability false पर सेट करने के बाद।

i.e button.setFocusable(false);

और अपनी पंक्ति के अपने लेआउट कंटेनर के लिए android:descendantFocusability="blocksDescendants" भी सेट करें। आप सीधे android:focusable="false" सेट कर सकते हैं लेकिन इससे आपका बटन क्लिक करने योग्य नहीं होगा।

+10

सेटिंग एंड्रॉइड: पंक्ति के लेआउट कंटेनर पर अवरोधक फोकसबिलिटी = "ब्लॉक डिस्कान्डेंट्स" मेरे लिए इस समस्या को हल करने के लिए पर्याप्त था। मुझे बटन की फोकस करने योग्य संपत्ति के साथ कुछ भी करने की ज़रूरत नहीं थी। – harmanjd

+0

यहां तक ​​कि बेहतर समाधान, क्योंकि यह अधिक घोषणात्मक और उच्च स्तर है। बहुत अच्छा। – Marchy

संबंधित मुद्दे