2010-02-02 13 views
5

मैं एक ऐप्स जिसका मुख्य वर्ग फैली ListActivity है:सूचीदृश्य पहले से ही मौजूद साथ एक रपट दराज के अंदर सूचीदृश्य को लागू करने

public class GUIPrototype extends ListActivity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     final Cursor c = managedQuery(People.CONTENT_URI, null, null, null, null); 
     String[] from = new String[] {People.NAME}; 
     int[] to = new int[] { R.id.row_entry }; 
     SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.drawer,c,from,to); 


     setListAdapter(adapter); 
     getListView().setTextFilterEnabled(true); 
    } 
} 

मैं एक रपट दराज मेरी एक्सएमएल में शामिल किया है, और मैं एक पाने के लिए कोशिश कर रहा हूँ स्लाइडिंग ड्रॉवर में दिखाई देने के लिए अलग सूचीदृश्य। मैं एक inflater का उपयोग कर दूसरी सूचीदृश्य पॉप्युलेट करने के लिए कोशिश कर रहा हूँ:

View inflatedView = View.inflate(this, R.layout.main, null); 
ListView namesLV = (ListView) inflatedView.findViewById(R.id.content); 
String[] names2 = new String[] { "CS 345", "New Tag", "Untagged" }; 
ArrayAdapter<String> bb = new ArrayAdapter<String>(this, R.layout.main, R.id.row_entry, names2); 
namesLV.setAdapter(bb); 

यह संकलित, और रन है, लेकिन पूरी तरह से slidingdrawer खाली है। मेरे एक्सएमएल इस प्रकार है:

<SlidingDrawer 
    android:id="@+id/drawer" 
    android:handle="@+id/handle" 
    android:content="@+id/content" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_gravity="bottom"> 

    <ImageView 
     android:id="@id/handle" 
     android:layout_width="48px" 
     android:layout_height="48px" android:background="@drawable/icon"/> 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@id/content"/> 
</SlidingDrawer> 

मुझे लगता है कि मैं एक महत्वपूर्ण कदम याद कर रहा हूँ। मुझे गुगलिंग द्वारा मेरी समस्या पर कोई संसाधन नहीं मिला है, इसलिए किसी भी मदद की सराहना की जाएगी।

संपादित करें: यह बहुत समय पहले एक समस्या के लिए था, और मुझे जो समाधान मिला वह सिर्फ मेरे लेआउट को फिर से डिजाइन करना था। मैं एक जवाब स्वीकार करने में असमर्थ हूं क्योंकि मेरे पास परीक्षण करने का साधन नहीं है।

+0

मुझे इस सवाल का जवाब स्वीकार करने में सक्षम नहीं होने के कारण बुरा लगता है। हमने इस मुद्दे से पूरी तरह से बचने के लिए हमारे यूआई के लिए एक और मार्ग तय करने का फैसला किया है, और इसलिए मेरे पास उत्तर स्वीकार करने का कोई वास्तविक आधार नहीं है :( – Parker

उत्तर

0

ऐसा लगता है कि समस्या यह हो सकती है कि आप अपने दृश्य में एक का उपयोग करने के बजाय ListView का एक नया उदाहरण बढ़ा रहे हैं।

ListView listView = (ListView) findViewById(R.id.content);

साथ ListView रही तो यह करने के लिए अपने एडाप्टर लागू की कोशिश करो।

+0

या तो संयोजन के परिणामस्वरूप नलपोइंटर अपवाद में परिणाम होता है। – Parker

0

आप की कोशिश की

View inflatedView = View.inflate(this, R.layout.main, null); 
SlidingDrawer sliding=(SlidingDrawer) inflatedView.findViewById(R.id.drawer); 
ListView namesLV = (ListView) sliding.findViewById(R.id.content); 
1

मुझे लगता है मैं समाधान हो सकता है है।

इन सभी उपरोक्त समाधानों ने मेरे लिए काम नहीं किया।

लेकिन फिर, मैंने जो किया वह क्लिकक्लिक लिस्टनर को वास्तविक दृश्य में जोड़ा गया जो मैं एडाप्टर से वापस आया और बीएएम ने मेरे लिए काम करना शुरू कर दिया। मेरी अनुकूलक में onClickListener जोड़ने के लिए था

मई लेआउट एक्सएमएल (पूरा नहीं एक ....)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/details" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ScrollView 
     android:id = "@+id/scrolling" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <RelativeLayout 
      android:paddingBottom="30dip" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     <ImageView 
      android:id="@+id/listingIcon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true"/> 
     ............ 
    </ScrollView> 
    <SlidingDrawer 
     android:id="@+id/slidingDrawerShowMore" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:topOffset="132dip" 
     android:handle="@+id/handle" 
     android:content="@+id/content"> 
     <LinearLayout 
      android:id="@+id/handle" 
      android:padding = "5dip" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/black"> 
      <TextView 
       android:id="@+id/title" 
       android:layout_alignParentRight="true" 
       android:textSize="14dp" 
       android:layout_below="@id/rate" 
       android:singleLine="true" 
       android:textColor="#3F48CC" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/show_more"/> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@id/content" 
      android:layout_width="match_parent" android:layout_height="match_parent" 
      android:orientation="vertical" android:gravity="center" 
      android:background="@android:color/black"> 
      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_gravity="center_vertical" 
       android:background="@drawable/dark_header"> 
       <TextView 
        android:id="@+id/otherTitle" 
        android:layout_alignParentRight="true" 
        android:layout_below="@id/rate" 
        android:singleLine="true" 
        android:textSize="21px" 
         android:paddingLeft="10px" 
        android:textColor="#EBEBEB" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_vertical" 
        android:layout_weight="0.6" 
        android:text="@string/someString"/> 
       <ProgressBar 
        android:id="@+id/pbar" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        style="@android:style/Widget.ProgressBar.Small" 
        android:layout_gravity="center_vertical"/> 
      </LinearLayout> 
      <ListView 
       android:id="@+id/listview" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"/> 
     </LinearLayout> 
    </SlidingDrawer> 
</RelativeLayout> 

अब घटनाओं क्लिक सब मैं करना था संभालने के लिए:

यहाँ नमूना कोड है

public View getView(int position, View convertView, ViewGroup parent) { 
      convertView.setOnClickListener(this); 
} 

यह है कि। समस्या यह है कि मैं इस सूची दृश्य के लिए काम कर रहा हूं ITemClickListener पर नहीं मिल सका। लेकिन अभी क्लिक श्रोता मेरे लिए काम करता है। एक दिन मुझे इसके पीछे कारण पता लगाना अच्छा लगेगा।

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