2012-09-05 15 views
6

तो मेरे पास सूची दृश्य के लिए बटन के साथ कस्टम सूची आइटम है। दबाए जाने पर, बटन उपयोगकर्ता को फीडबैक दिखाने के लिए वैकल्पिक ड्रॉइंग प्रदर्शित करता है। हालांकि जब मैं पंक्ति पर क्लिक करता हूं, तो हर बटन दबाए गए राज्य को दिखाता है जैसे कि मैंने उन पर क्लिक किया है।ListItem के अंदर बटन को कैसे रोकें

मैं बटन को राज्य_प्रेस के बजाय अपनी मूल स्थिति कैसे प्रदर्शित करूं?

लेआउट/सूची आइटम:

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:paddingBottom="10dp" 
    android:paddingTop="10dp" 
    android:descendantFocusability="blocksDescendants" > 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:gravity="center_vertical|left" > 

     <TextView 
      android:id="@+id/txtMain" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      style="@style/PrimaryText" /> 

     <TextView 
      android:id="@+id/txtSub" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      style="@style/SecondaryText" /> 
    </LinearLayout> 

    <ImageButton 
     android:id="@+id/imbResponse" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:focusable="false" 
     android:duplicateParentState="false" 
     android:src="@drawable/response_btn" 
     android:contentDescription="@string/response" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginBottom="5dp" /> 
</LinearLayout> 

drawable/response_btn.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_focused="true" android:drawable="@drawable/res_m" /> 
    <item android:state_pressed="true" android:drawable="@drawable/res_m" /> 
    <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/res_alt_m" /> 
</selector> 

मैं state_focused हटाने और state_pressed, state_focused कोशिश की है। ऐसा लगता है कि बटन अपने माता-पिता से राज्य_प्रेस किया गया है।

+0

कोई भाग्य समाधान ढूंढ रहा है? – Sunkas

उत्तर

0

im मेरी राय आप के रूप में android:duplicateParentState="false"

माता पिता से राज्य को निष्क्रिय करने के लिए अपने Button

+0

जो मैंने किया;)। यह वैसे भी ImageButton है। – RobGThai

+0

आपके लेआउट में भी –

+5

कोशिश की, हालांकि कोई फर्क नहीं पड़ता। – RobGThai

1

में जोड़ना यह मेरा एप्लिकेशन काम कठिन बना देता है, लेकिन यह समस्या का हल की जरूरत है:

... 
mImageIcon.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       v.setBackgroundResource(R.drawable.my-background); 
       break; 
      case MotionEvent.ACTION_UP: 
      case MotionEvent.ACTION_CANCEL: 
       /* 
       * You can use another background rather than 0. 
       */ 
       v.setBackgroundResource(0); 
       break; 
      } 

      return false; 
     }// onTouch() 
    }); 
+0

क्या आप इस समाधान को समझा सकते हैं? –

4

मुझे पता चला कि पेरेंट व्यू में android:clickable="true" सेटिंग करने से बच्चे के विचारों को बदल दिया जाएगा।

this answer देखें।

1

मुझे यह समस्या भी है, मैं इसे Google करता हूं और इसे लगभग 3 घंटे तक आजमाता हूं! अब मुझे समाधान मिला। बस बच्चे के दृश्य पर OnClickListener जोड़ें। और ऑनक्लिक विधि में कुछ भी नहीं करते हैं। यह 2.3 एमुलेटर और मेरे नेक्सस पर काम करता है 5.

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