如何在另一个活动的按钮单击时打开/显示viewflipper的子项 [英] How to open/display viewflipper's child on button click from another activity

查看:79
本文介绍了如何在另一个活动的按钮单击时打开/显示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

推荐答案

您的上述代码看起来还不错,但是如果它仍然无法正常工作那么做。

从活动A中膨胀viewpager并将其标记为公开。您可以将此用于活动B,因为您已将其标记为公开。



您还可以使用已经消失的可见性并再次显示按钮点击。
Your above code looks ok but if it's still not working then do one thing.
Inflate viewpager from Activity A and mark it as public. You can use this to activity B as you have marked it as public.

You can also play with visibility gone and again shown on button clicks.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆