3

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


            }});
EI756
  • 557
  • 1
  • 8
  • 19

2 Answers2

1

Another Option Here:

You can always do viewFinder.setDisplayedChild(0), where the number matches the view you want to display. This lets you select which view to display at any time.

Piggybacking off of the previous answer:

@overide public void onBackPressed() 
     {     
     viewFinder.setDisplayedChild(0)

      }

This lets you use the viewflipper more dynamically than simply using the .next() and .previous() methods. So for example you could move have multiple menus, and allow access to all of them from one another.

EX:

   someButton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        viewfinder.setDisplayedChild(1);
    }
   });

Hope that helps.

Nathaniel
  • 457
  • 5
  • 14
1

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

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • ok but there doesn't seem to be a back button visible in the current view – EI756 Aug 26 '11 at 19:11
  • "have a back button on the second listview" means? you want to add any button on top of listview or just use android device's defalut back key? – user370305 Aug 26 '11 at 19:15
  • Well preferably I want to add a back button on the second listview – EI756 Aug 26 '11 at 19:26
  • see my edited answer. If you find this is helpful to you please voteup and mark it as correct answer for other user. Thnx. – user370305 Aug 26 '11 at 19:43