5

I have an app whose main class extends 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);
    }
}

I have a sliding drawer included in my XML, and I'm trying to get a separate listview to appear in the sliding drawer. I'm trying to populate the second listview using an 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);

This compiles, and runs, but the slidingdrawer is completely blank. My XML follows:

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

I feel like I'm missing a vital step. I haven't found any resources on my problem by Googling, so any help would be greatly appreciated.

Edit: This was for a problem a long time ago, and the solution I found was to just redesign my layout. I am unable to accept an answer as I don't have the means to test them.

4

3 回答 3

1

我想我可能已经找到了解决方案。

以上所有这些解决方案都对我不起作用。

但是后来,我所做的是将 onClickListener 添加到我从适配器返回的实际视图中,BAM 它开始为我工作。

这是示例代码:

可布局 XML(不完整一个....)

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

现在要处理点击事件,我所要做的就是在我的适配器中添加 onClickListener

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

而已。问题是我无法让我的 onItemClickListener 为这个 ListView 工作。但现在点击监听器对我有用。有一天,我很想找出这背后的原因。

于 2011-11-17T21:20:29.987 回答
0

看起来问题可能是您正在膨胀 ListView 的一个新实例,而不是在您的视图中使用该实例。

尝试获取 ListViewListView listView = (ListView) findViewById(R.id.content);

然后将您的适配器应用于它。

于 2010-02-03T14:17:01.757 回答
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);
于 2010-08-23T09:27:01.863 回答