Par*_*ker 5 android android-widget
我有一个应用程序,其主类扩展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);
}
}
Run Code Online (Sandbox Code Playgroud)
我的XML中包含一个滑动抽屉,我正试图在滑动抽屉中显示单独的列表视图.我正在尝试使用inflater填充第二个listview:
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);
Run Code Online (Sandbox Code Playgroud)
这会编译并运行,但是抽屉是完全空白的.我的XML如下:
<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>
Run Code Online (Sandbox Code Playgroud)
我觉得我错过了一个重要的步骤.我没有通过谷歌搜索找到任何有关我的问题的资源,所以任何帮助将不胜感激.
编辑:很久以前这是一个问题,我找到的解决方案是重新设计我的布局.我无法接受答案,因为我没有办法测试它们.
看起来问题可能是您正在膨胀 ListView 的新实例,而不是使用视图中的实例。
尝试获取 ListViewListView listView = (ListView) findViewById(R.id.content);
然后将适配器应用到它。
| 归档时间: |
|
| 查看次数: |
6359 次 |
| 最近记录: |