1

我想在用户可以在一个或多个视图实例之间来回翻转的区域中显示来自光标的数据。我正在尝试使用 Gallery 小部件,因为它已经支持适配器并且会自动接收来自内容提供者的更新通知。我考虑使用 ViewFlipper,但由于适配器支持,我先去了 Gallery。如果我不能让它工作,我最终会尝试 ViewFlipper 并注册为光标上的内容观察者。

我现在所拥有的看起来应该可以工作,而且似乎可以工作,只是我实际上在屏幕上看不到任何东西。包含画廊视图的活动有一个选项菜单。当我按下菜单按钮并显示活动的菜单时,会出现画廊中光标的文本。隐藏菜单后,图库内容会再次消失。此外,当在图库上向左或向右滑动时,我可以看到到达视图远端后应该显示的文本。

我的活动布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Gallery android:id="@+id/host_gallery"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center|fill"
    />

</LinearLayout>

我的画廊内容布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge"
    />

</LinearLayout>

我的活动的 onCreate:

private Gallery mGallery;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.host);

    mGallery = (Gallery) findViewById(R.id.host_gallery);

    Cursor c = managedQuery(Host.CONTENT_URI, null, null, null, null);
    mGallery.setAdapter(new SimpleCursorAdapter(this, R.layout.host_item, c,
        new String[] { "name" },
        new int[] { R.id.name }));
}

谁能看到我在这里做错了什么,或者画廊不会做我想做的事?

4

0 回答 0