本文介绍了如何在另一个活动的按钮单击时打开/显示viewflipper的子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开viewflippers chiild从按钮点击另一个活动

在活动A我有两个按钮点击事件和活动B我有一个viewflipper

两个布局与不同的ID。当我点击活动A中的button1时我想要它

在活动B中显示子1(布局1 @ + id / first),按钮2也是如此。请参阅下面的代码



活动A

i will like to open viewflippers chiild from button click in another activity
in activity A i have two buttons with click event and in activity B i have a viewflipper
with two layout with different ids. when i click on button1 in activity A i want it to
show child 1 (layout 1 @+id/first) in activity B the same goes for button 2. see my code below

Activity A

button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i=new Intent(ActivityA.this, ActivityB.class);
                //code to pick and display certian or particular layout goes here
                startActivity(i);
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i1=new Intent(ActivityA.this, ActivityB.class);
                //code to pick and display certian or particular layout goes here
                startActivity(i1);
            }
        });





XML B和活动B





XML B and Activity B

<ViewFlipper

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:id="@+id/viewFlipper"

    android:layout_alignParentTop="true"

    android:layout_alignParentLeft="true"

    android:layout_alignParentStart="true">
 
    <LinearLayout

        android:orientation="vertical"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:id="@+id/first">
 
        <!-- more views -->
 
    </LinearLayout>
 
    <LinearLayout

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:id="@+id/second">
 
        <!-- more views -->
 
    </LinearLayout>
 
    <LinearLayout

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:id="@+id/third">
 
        <!-- more views -->
         
    </LinearLayout>
</ViewFlipper>







ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
// 2 is the index for the 3rd child
viewFlipper.setDisplayedChild(2);
// or when you don't know the index but the ID of the view
viewFlipper.setDisplayedChild( viewFlipper.indexOfChild(findViewById(R.id.third)) );





亲切帮助



我尝试了什么:



已搜索堆栈溢出



kindly help

What I have tried:

have searched stacked overflow

推荐答案


这篇关于如何在另一个活动的按钮单击时打开/显示viewflipper的子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:26