开发者

how to pass variable to the next view using viewflipper

开发者 https://www.devze.com 2023-02-08 06:52 出处:网络
I have a problem regarding the following: public void onItemClick(AdapterView<?> a, View v, int position, long id) {

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();
   开发者_如何学C  }  
     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.


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?


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").

0

精彩评论

暂无评论...
验证码 换一张
取 消