Search code examples
androidback-buttonviewflipper

Android: How do I implement a back button into a view flipper


I'm using a view flipper with tabs at the top of the view. I have a listview under the tabs, clicking an item on the list brings the user to another listview (still within the same view flipper).

What I would like to do is have a back button on the second listview, so the user can go back to the first list. I know I can use the viewflipper.showPrevious() function to go back, but how do I go about creating a back button and attaching this function to it?

Thanks in advance, Here's the layout code:

        <ViewFlipper android:id="@+id/layout_tab_one"
            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" />
        <ListView android:id="@+id/listview2" 
            android:layout_width="fill_parent" android:layout_height="wrap_content" />


        </ViewFlipper>

Activity code:

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


            }});

Solution

  • just override the

         @overide public void onBackPressed() 
             {     
              // your code for previouse list; 
    
              }
    

    EDIT:just use ListView.addHeaderView(View v) and ListView.addFooterView(View v) android listviews: header and footer views