将图库小部件与非图像数据一起使用

发布于 2024-10-21 12:28:35 字数 1906 浏览 6 评论 0原文

我想在用户可以在一个或多个视图实例之间来回翻转的区域中显示来自光标的数据。我正在尝试使用图库小部件,因为它已经具有适配器支持并且会自动接收来自内容提供商的更新通知。我考虑使用 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 }));
}

任何人都可以看到我在这里做错了什么,还是画廊不会做我想要的事情?

I want to display data from a cursor in an area that the user can flip back and forth between one or more instances of a view. I am attempting to use the Gallery widget, since it already has Adapter support and would automatically receive update notifications from a content provider. I looked at using a ViewFlipper, but went went Gallery first due to the adapter support. If I can't get it working, I will end up trying a ViewFlipper and registering as a content observer on the cursor.

What I have now looks like it should be working, and sort of seems to be, except that I can't actually see anything on the screen. The activity that houses the Gallery view has an options menu. When I press the menu button and the activity's menu is displayed, the text from the cursor in the Gallery appears. When the menu is hidden, the Gallery content disappears again. Additionally, when swiping left or right on the Gallery, I can see the text that should be displayed once it reaches the far edge of the view.

My activity layout:

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

My Gallery content layout:

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

My Activity's 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 }));
}

Can anyone see what I am doing wrong here, or will the Gallery just not do what I want it to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文