问题描述:

I have written code to go to next view by selecting the perticular item in the list.

list contains many items I want to show differnt textview on differnt Item selection.

I have a problem regarding the following code..

listview.setOnItemClickListener(new OnItemClickListener(){

@Override

public void onItemClick(AdapterView<?> a, View v, int position, long id) {

temp=a.getItemAtPosition(position).toString();

if (temp=="Aries")

{

ViewFlipper viewflipper= (ViewFlipper) findViewById(R.id.viewflipper);

TextView text = (TextView) v.findViewById(R.id.item1);

viewflipper.showNext();

}

if (temp=="Taurus")

{

ViewFlipper viewflipper= (ViewFlipper) findViewById(R.id.viewflipper);

viewflipper.showNext();

TextView text = (TextView) v.findViewById(R.id.item2);

}

xml is..

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<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/item1"

android:background="@drawable/aries28"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="This is for me"

/>

<TextView

android:id="@+id/item2"

android:background="@drawable/t28"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="This is for you"

/>

</ViewFlipper>

</AbsoluteLayout>

However, when I run this code it is showing same textview in the next view for both the items, i.e. it is showing same thing("This is for Me"). How can I solve this problem?

Thanks in advance..

网友答案:

that's because you are not skipping the next view to the list which is TextView "this is for my". If you do showNext() flipper will always shows you the next view declared in the xml layout, so, kip the second view with viewflipper.setDisplayedChild(whichChild);

cheers

相关阅读:
Top