2010-02-02 38 views
5

Tôi có một ứng dụng mà chính lớp kéo dài ListActivity:Thực hiện một listview bên trong một ngăn kéo trượt với một listview đã hiện diện

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); 
    } 
} 

Tôi có một ngăn kéo trượt bao gồm trong XML của tôi, và tôi đang cố gắng để có được một listview riêng biệt xuất hiện trong ngăn kéo trượt. Tôi đang cố gắng điền vào listview thứ hai bằng cách sử dụng một 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); 

Việc biên dịch và chạy, nhưng trình rút bỏ hoàn toàn trống. XML My sau:

<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> 

tôi cảm thấy như tôi là thiếu một bước quan trọng. Tôi đã không tìm thấy bất kỳ tài nguyên nào về vấn đề của tôi bởi Googling, vì vậy mọi trợ giúp sẽ được đánh giá cao.

Chỉnh sửa: Vấn đề này đã xảy ra một thời gian dài trước đây và giải pháp mà tôi tìm thấy là thiết kế lại bố cục của tôi. Tôi không thể chấp nhận câu trả lời vì tôi không có phương tiện để kiểm tra chúng.

+0

Tôi cảm thấy xấu vì không thể chấp nhận câu trả lời cho câu hỏi này. Chúng tôi quyết định đi một tuyến đường khác cho giao diện người dùng của chúng tôi để tránh hoàn toàn vấn đề này và vì vậy tôi không có cơ sở thực sự để chấp nhận câu trả lời: ( – Parker

Trả lời

0

Có vẻ như vấn đề có thể là bạn đang tăng cường một phiên bản mới của một ListView thay vì sử dụng một phiên bản trong chế độ xem của bạn.

Hãy thử nhận được ListView với ListView listView = (ListView) findViewById(R.id.content);

Sau đó áp dụng bộ chuyển đổi của bạn với nó.

+0

Kết quả kết hợp trong NullPointerException, thật đáng buồn. – Parker

0

Các bạn đã thử

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

Tôi Giả sử tôi có thể đã tìm thấy các giải pháp.

Tất cả các giải pháp trên không hiệu quả đối với tôi.

Nhưng sau đó, những gì tôi đã làm là thêm onClickListener vào chế độ xem thực tế mà tôi quay trở lại từ bộ điều hợp và BAM nó bắt đầu hoạt động cho tôi.

Đây là đoạn mã mẫu:

tháng layout XML (Không hoàn thành một ....)

<?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> 

Bây giờ để xử lý các sự kiện bấm tất cả tôi phải làm là để thêm OnClickListener trong bộ chuyển đổi của tôi

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

Vậy đó. Vấn đề là tôi không thể có được onItemClickListener làm việc cho ListView này. Nhưng ngay bây giờ trên trình nghe nhấp chuột hoạt động cho tôi. Một ngày nào đó tôi rất muốn tìm ra lý do đằng sau điều này.

Các vấn đề liên quan