2012-01-28 16 views
6

काम नहीं कर रहा है तो वास्तव में मेरे पास एक सूची है जो एक कस्टम एडाप्टर के साथ देखें और यह एक दृश्य को बढ़ाता है जिसमें क्षैतिज स्क्रॉलव्यू के साथ-साथ एक टेक्स्टव्यू इत्यादि भी शामिल है। समस्या यह है कि जब मैं श्रोता संलग्न करने का प्रयास करता हूं इस सूची में देखें कि इसे कोई कॉलबैक नहीं मिल रहा है।क्षैतिज ScrollView OnItem के साथ ListView

मुझे विश्वास है कि समस्या को इस तथ्य के साथ करना है कि मेरी सूची आइटम में एक स्क्रॉल व्यू है जो क्लिक ईवेंट को रोक रहा है (हालांकि मैंने सोचा था कि इसे केवल अन्य संकेतों को रोकना चाहिए)।

कोड ... (मेरी सूची में आइटम एक्सएमएल)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearMain" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:orientation="vertical" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/grey" > 

     <TextView 
      android:id="@+id/headerName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:padding="4dp" 
      android:textColor="@color/text_header" 
      android:textStyle="bold" 
      android:text="TextView" /> 

    </RelativeLayout> 
    <View 
     android:background="@color/border" 
     android:layout_width="fill_parent" 
     android:layout_height="1px" /> 
    <HorizontalScrollView 
     android:id="@+id/horizontalScrollView1" 
     android:layout_width="fill_parent" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:id="@+id/linearImages" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:padding="4dp"> 
     </LinearLayout> 
    </HorizontalScrollView> 
    <View 
     android:background="@color/border" 
     android:layout_width="fill_parent" 
     android:layout_height="1px" /> 
</LinearLayout> 

और फिर मेरी onCreate में ...

lv.setAdapter(myobj.adapter); 
    lv.setTextFilterEnabled(true); 
    lv.setOnItemClickListener(new OnItemClickListener(){ 

     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
       long arg3) { 
      // TODO Auto-generated method stub 
      Log.w("dsdsds", "sdsdsds"); 
     }}); 

कोई मदद या सुझाव हो सकता है बहुत सराहना

+0

किसी भी सलाह बहुत अच्छा होगा – Maurycy

+0

तो जवाब में से कोई भी वास्तव में इसे ठीक है और मैं कोड के लिए पहुँच नहीं है अब और आधार अगर कोई इस मुद्दे पर आता है और एक ज्ञात फिक्स है तो मैं – Maurycy

उत्तर

1

आप कर सकते हैं लाइनर के लिए setOnClickListener कॉल करें अपने एडाप्टर के getView() विधि में मुख्य।

1

scrollview के लिए आप OnTouchListener का उपयोग करना चाहिए, जैसे:

private class ScrollViewOnTouchListener implements OnTouchListener{ 
     HorizontalScrollView view; 
     float historicX = Float.NaN; 
     static final int DELTA_ON_CLICK = 20; 
     long historicTime; 
     int position; 
     public ScrollViewOnTouchListener(HorizontalScrollView view, int position){ 
      this.view = view; 
      this.position = position; 
     } 

     @Override 
     public boolean onTouch(View v, MotionEvent event) 
     { 
      switch (event.getAction()) 
      { 
       case MotionEvent.ACTION_DOWN: 
       historicX = event.getX(); 
       historicTime = System.currentTimeMillis(); 
       break; 

       case MotionEvent.ACTION_UP: 

       if (Math.abs(event.getX() - historicX) < DELTA_ON_CLICK) 
        // seems like onclick 
        // do what you want for onClick 

       break; 
       default: return false; 
      } 
      return true; 
     } 


    } 

और एडाप्टर के getView विधि में:

public View getView(int position, View convertView, ViewGroup parent) { 
    ... 
    HorizontalScrollView scrollItem; 
    scrollItem =( HorizontalScrollView)itemView.findViewById(R.id.item_scroll_view); 
    scrollItem .setOnTouchListener(new ScrollViewOnTouchListener(scrollItem , position));  
} 
2

सर्वोच्च लेआउट को यह करें:

android:descendantFocusability="blocksDescendants"

यह मेरे लिए चाल है, अब ItemClickListener पर निकाल दिया जा रहा है।

+0

स्वीकार करूँगा धन्यवाद यह मेरे लिए उपयोगी है .. –

+0

कहां रखना है - सूची आइटम के मूल लेआउट में? आइटम लेआउट में – NarendraJi

+0

@DroidWormNarendra हाँ –

0

अंदर list_item.xml कुछ आईडी के साथ अपने लेआउट को चिह्नित:

<?xml version="1.0" encoding="utf-8"?> 
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
         xmlns:tools="http://schemas.android.com/tools" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:fillViewport="true"> 

    <LinearLayout 
     android:id="@+id/layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

... 

अपने कस्टम एडाप्टर खोलें, getView(...) लिखने में:

layout = view.findViewById(R.id.layout); 
layout.setTag(position); 
layout.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (callback != null) { 
       callback.showItem(getItem((int) v.getTag())); 
      } 
     } 
    }); 
नीचे एडाप्टर लिखने में

:

public interface OnClickInterface { 
    void showItem(YourClass item); 
} 

और एडाप्टर के निर्माता में कॉलबैक असाइन करें:

public CustomAdapter(Context context, List<YourClass> list, OnClickInterface callback, int resId) { 
    this.callback = callback; 
    ... 

अपनी गतिविधि में/टुकड़ा एक ListView तो जैसे एक एडाप्टर बनाने में शामिल है कि:

CustomAdapter.OnClickInterface callback = new CustomAdapter.OnClickInterface() { 
     @Override 
     public void showItem(YourClass item) { 
      // Do something with an item. 
     } 
} 
adapter = new Customdapter(getActivity(), new ArrayList<YourClass>(), callback, R.layout.list_item); 
संबंधित मुद्दे