开发者

Using a Gallery widget with non-Image data

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 t开发者_StackOverflow社区he 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜