如何使用ListView和一个ViewFlipper导航用户在一个Android应用程序?

问题描述:

我想建立一些菜单式的导航我的应用程序。

I want to set up some menu-like navigator for my app.

目前在主页一个ListView,它包含两个项目,点击每一个将展示其与ViewFlipper子视图,并且如果用户单击后退按钮,他将返回到首页了。

There is a listView in the main page and it contains two items, click each one will show its child view with ViewFlipper, and if user clicked the back button, he will return to the homepage again.

现在的问题是如何做到最好的,我只能用ViewFlipper翻转到下一个屏幕或preV屏,如何在这里管理这些孩子的意见?如何把它们放在我的布局xml文件?

The question is how to make it, I can only use ViewFlipper to flip to next screen or prev screen, how to manage these child views here? How to put them in my layout xml file?

这里有个psudo路做这件事的。

Here follows a psudo-way of doing it.

//在OnCreate中,增加一个点击监听到你的列表视图,让视图翻转到下一个视图。

//In OnCreate, add a click listener to your listview to make the view flip to the next view.

viewflipper = (ViewFlipper) findViewById(R.id.viewflipper);
listview = (ListView) findViewById(R.id.listview);


listview.setOnItemClickListener(new OnItemClickListener(){
  public void onItemClick(AdapterView<?> a, View v, int position, long id) {
     viewflipper.showNext();

});

//重写的onkeydown在你Activty处理后退按钮的点击。

// Override the onKeyDown in you Activty to handle the back button click.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if(viewflipper.getVisibleChild() != 0){
           viewflipper.showPrevious();
           return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

// XML的viewflipper圣维特列表视图为第一页和一个简单的TextView作为第二页

// xml for a viewflipper vith the listview as "firstpage" and a simple textview as the "second page"

<ViewFlipper android:id="@+id/viewflipper" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        > 
        <ListView android:id="@+id/listview" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
        /> 
        <TextView android:id="@+id/secondview" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:text="This is the second view" 
        /> 
</ViewFlipper>