2016-04-22 15 views
20

मुझे पता है कि TextView के लिए xml में android:textIsSelectable="true" सेटिंग मूल पाठ चयन पॉपअप दिखाएगी और मैं इसे अपने एप्लिकेशन में उपयोग कर रहा हूं। लेकिन मुझे क्या मिला ।"एंड्रॉइड: textIsSelectable =" true "RecyclerView में टेक्स्ट व्यू के लिए काम नहीं कर रहा है

TextView: TextView does not support text selection. Action mode cancelled. 

और मैं पता नहीं क्यों - जब मैं एक दृश्य RecyclerView से जुड़ी जब भी मैं पाठ निम्नलिखित लॉग प्रकट होता है के चयन का प्रयास में एक ही विशेषता सेट करने का प्रयास यह किसी भी अधिक काम नहीं कर रहा? यह अन्य स्क्रीन पर क्यों काम करता है और RecyclerView के साथ नहीं। मैंने कई पोस्ट पढ़े -

TextView with android:textIsSelectable="true" not working in listview

textview textIsSelectable="true" not working in Listview

android:textIsSelectable="true" for TextView inside Listview does not work

लेकिन तब मैं इस पोस्ट का सामना करना पड़ा -

Android: "TextView does not support text selection. Action mode cancelled"

और @hungkk द्वारा जबाब मेरे लिए काम किया। उनके समाधान ने TextView चौड़ाई match_parent से wrap_content में बदलने के लिए चौड़ाई का सुझाव दिया।

मुझे पता है कि मैं यह कर सकता हूं लेकिन मेरा सवाल यह है कि इस मुद्दे को कैसे ठीक किया गया क्योंकि यह मेरे लिए अजीब लग रहा है। और, अगर मैं चौड़ाई को match_parent पर रखना चाहता हूं तो समाधान क्या है।

किसी भी इनपुट का स्वागत है।

+1

क्या आप चयन के साथ कर रहे हैं? (मार्टी या शदाब)। मुझे 'match_parent' या' wrap_content' के लिए 'View.OnClickListener()' का उपयोग करके कोई समस्या नहीं है। – Gary99

+0

वियर्ड लेकिन मैंने कुछ पोस्टों में पढ़ा है कि जब रीसाइक्लर का दृश्य सेल का पुन: उपयोग करता है, तो टेक्स्टव्यू मिलान_पैरेंट पर सेट होने पर यह चयन योग्य टेक्स्ट सुविधा अक्षम करता है। क्या आपने एंड्रॉइड की बजाय 'android: inputType =" textMultiLine "'सेटिंग सेट करने का प्रयास किया है: textIsSelectable =" true "' वर्कअराउंड के रूप में? – fmaccaroni

उत्तर

2

यदि आप पुनर्नवीनीकरण या सूचीदृश्य में एंड्रॉइड: descendantFocusability = "blockDescendants" जोड़ते हैं, तो इसे हटा दें। और यह जांचने के बाद

0

ऐसा लगता है कि इसमें कई समस्याएं हैं और संकेत हैं कि यह एंड्रॉइड कोड में एक बग हो सकता है लेकिन मुझे कोई समस्या नहीं है। यह OnClickListener() और मूल चयन पॉपअप दोनों के लिए मेरे लिए काम करता है।

(किटकैट 4.4, Lollipop 5.1 और नूगा 7.1 पर परीक्षण किया गया) एडाप्टर

class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 
    TextView textView; 
    ImageView imageView; 

    MyViewHolder(View itemView) { 
     super(itemView); 
     textView = (TextView) itemView.findViewById(R.id.my_text_view); 
     imageView = (ImageView) itemView.findViewById(R.id.my_image_view); 

     itemView.setOnClickListener(this); 
     textView.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View view) { 
     // this shows 'my_text_view' when the text is clicked or 
     //  'my_item' if elsewhere is clicked 
     Log.d(TAG, "view = " + view.toString()); 
     switch (view.getId()) { 
      case R.id.my_item: 
       break; 
      case R.id.my_text_view: 
       break; 
     } 
    } 
} 

और मेरे आइटम लेआउट

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/my_item" 
    > 

    <ImageView 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:background="@color/colorPrimary" 
     android:id="@+id/my_image_view" 
     /> 

    <!-- this works for me with either "match_parent" or "wrap_content" for width --> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="20dp" 
     android:text="My text view" 
     android:textIsSelectable="true" 
     android:id="@+id/my_text_view" 
     /> 
</LinearLayout> 
0

recyclerview के मुख्य अभिभावक लेआउट में विशेषता जोड़ें

android:descendantFocusability="beforeDescendants"

और फिर पंक्तिबद्ध लेआउट के टेक्स्टव्यू में

android:textIsSelectable="true" 
0

आपका RecyclerView एडाप्टर में जोड़ें:

public ViewHolder(View itemView) { 
      super(itemView); 
      txtDate = (TextView) itemView.findViewById(R.id.txtDate); 
      txtDate.setTextIsSelectable(true); 
} 

अपने मेरे लिए काम किया ..

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