how to pass variable to the next view using viewflipper

1.2k views Asked by At

I have a problem regarding the following:

public void onItemClick(AdapterView<?> a, View v, int position, long id) {
    temp=a.getItemAtPosition(position).toString();
    Toast.makeText(ne.this, temp, Toast.LENGTH_SHORT).show();

     if (temp=="Aries")
     {
         ViewFlipper  viewflipper= (ViewFlipper) findViewById(R.id.viewflipper);
        Toast.makeText(ne.this, temp, Toast.LENGTH_SHORT).show();
     }  
     if (temp=="Taurus")
     {
         ViewFlipper  viewflipper= (ViewFlipper) findViewById(R.id.viewflipper);
        Toast.makeText(ne.this, temp, Toast.LENGTH_SHORT).show();
     }
     if (temp=="Libra")
     {
         ViewFlipper  viewflipper= (ViewFlipper) findViewById(R.id.viewflipper);
        Toast.makeText(ne.this, temp, Toast.LENGTH_SHORT).show();
     }  

when I click on the item it shows me the string on first view.but I am not going on to the second view. and also on first view when I click other item still it shows first output.

i.e. if I select Aries in the first view It shows me aries in the toast window but doesn't go to the second view. and again I am pressing other item say Taurus, still it shows Aries to me.

2

There are 2 answers

0
Paresh Mayani On

I think you are misunderstood with ViewFlipper control.

By this line: ViewFlipper viewflipper= (ViewFlipper) findViewById(R.id.viewflipper); , you are just initiate viewflipper control , you are not giving any command to load next or previous view.

I mean to say, there are showPrevious() and showNext() method to load previous or next view accordingly.

viewflipper.showPrevious()
viewflipper.showNext()

For example:

You need to implement something like that, i hope this suits your question:

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

});

Refer this example: How to use a ListView and a ViewFlipper to navigate user in an Android app?

0
Jean On

You need to compare strings with the .equals method, not by ==. Your temp is "Aries" but it is a different string than the one you are testing for equality against so your temp == "Aries" returns false. You need to write it temp.equals("Aries").