How to use a ListView and a ViewFlipper to navigate user in an Android app?

左心房为你撑大大i 提交于 2019-12-04 15:04:00
Vidar Vestnes

Here follows a psudo-way of doing it.

//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();

});

// 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 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> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!