2012-10-01 20 views
5

स्क्रॉल नहीं करता है मैंने एक ऐप बनाया जिसमें दो टुकड़े हैं और दोनों टुकड़ों में सूचीदृश्य हैं। खंड 1 में पहली सूचीदृश्य स्क्रॉल हो रहा है और आइटम भी हाइलाइट किए जा रहे हैं। लेकिन दूसरे खंड में, सूचीदृश्य स्क्रॉल नहीं किया गया है और यहां तक ​​कि आइटम हाइलाइट नहीं हो रहे हैं। क्या कोई मुझे बता सकता है कि समस्या क्या है? यहां बात यह है कि मैंने एक्सएमएल में दोनों टुकड़ों में एक ही खंड वर्ग को रखने के साथ इसे अभी चेक किया है। या तो वे दोनों काम करना चाहिए या दोनों को नहीं करना चाहिए क्योंकि कोई दूसरे से अलग नहीं है। लेकिन यह समस्या क्यों होती है?सूचीफ्रेम में दूसरी सूचीदृश्य

मेरे टुकड़ा वर्ग:

public class Fragment1 extends ListFragment{ 

    String[] countries = new String[] { 
     "India", 
     "Pakistan", 
     "Sri Lanka", 
     "China", 
     "Bangladesh", 
     "Nepal", 
     "Afghanistan", 
     "North Korea", 
     "South Korea", 
     "Japan" 
    }; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
     return inflater.inflate(R.layout.fragment1,container,false); 
    } 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,countries); 
     setListAdapter(adapter); 
    } 

    public void onListItemClick(ListView parent, View v,int position, long id) 
    { 
     Toast.makeText(getActivity(), "You have selected "+countries[position], Toast.LENGTH_SHORT).show(); 
    } 

} 

main.xml:

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

    <fragment 
     android:name="com.example.listfragmentexample.Fragment1" 
     android:id="@+id/fragment1" 
     android:layout_weight="0.5" 
     android:layout_width="0dp" 
     android:layout_height="200dp" /> 

    <fragment 
     android:name="com.example.listfragmentexample.Fragment1" 
     android:id="@+id/fragment2" 
     android:layout_weight="0.5" 
     android:layout_width="0dp" 
     android:layout_height="300dp"/> 
</LinearLayout> 

fragment1.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:drawSelectorOnTop="false"/> 

</LinearLayout> 

उत्तर

3

तो, अपने कोड के अनुसार ऐसा लगता है कि आप बात कर रहे हैं आपके main.xml में दोनों टुकड़ों के लिए Fragment1 class। मुझे लगता है कि आपकी गतिविधि कक्षा में setContentView()ऑनक्रेट() विधि में शामिल है। चूंकि दोनों टुकड़े एक ही गतिविधि पर हैं, इसलिए संभावना है कि शुरुआत में केवल एक ही दृश्य को हाइलाइट किया जाए। मैंने अभी यह जांच की है, लेकिन यह ठीक काम कर रहा है। Just drag the listview in the second fragment, बल्कि आप इसे स्क्रॉल कर रहे हैं। यदि आप हाइलाइट करने के लिए अपना दूसरा सूचीदृश्य चाहते हैं, तो मुझे डर है कि आपको अलग-अलग एक्सएमएल फाइलों (खंड 1 और खंड 2 कहें) और टुकड़ों के लिए अलग-अलग वर्गों की आवश्यकता हो सकती है और निम्न कोड जोड़कर आपको पहले कभी भी आवश्यकता हो सकती है।

listView1 = (ListView)findViewById(R.id.listView1); 
listView1.requestFocus(); 

शुभकामनाएँ।

+0

हां। धन्यवाद। जब मैं दूसरी सूचीदृश्य को स्क्रॉल करने का प्रयास करता हूं, तो यह स्क्रॉल नहीं हो रहा है, भले ही मैं कर्सर रखूं और उसके आइटम पर क्लिक किया हो। तो, मैं उलझन में आया, लेकिन काम खींचें। कोई बात नहीं। ठीक है, दूसरे को हाइलाइट करने के लिए आपके सुझाव को लागू करने का प्रयास करेंगे। – Korhan