user1825740
user1825740

Reputation: 29

How to make buttons to appear and disappear on the Onclick event

I have 2 button invite and share, if i click on invite linearlayout bar1 will appear which contains 4 imageviews, and for share button also same linearlayout bar2 within that 4 imageview options, if i click on invite and share button both the layout bar appear, but for me when i click on invite or share only one corresponding bar should appear at a time...

Upvotes: 2

Views: 3151

Answers (2)

Vikalp Patel
Vikalp Patel

Reputation: 10877

Insert LinearyLayout upon your requirements

<merge>
<LinearLayout
    android:id="@+id/main"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:visibility="gone"  
    />
<LinearLayout
    android:id="@+id/sub"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:visibility="gone"  
    />  
</merge>

depending upon your invite and share button you can put these code invite.setOnClickListener() or share.setOnClickListener()

Insert Visibility of LinearLayout according to your Logic

LinearLayout mainLayout=(LinearLayout)this.findViewById(R.id.main);
LinearLayout subLayout=(LinearLayout)this.findViewById(R.id.sub);

invite.setOnClickListener(new OnClickListener()
{
   public void onClick(View v)
    {
    mainLayout.setVisibility(View.VISIBLE);        
    }
});

 share.setOnClickListener(new OnClickListener()
 {
   public void onClick(View v)
    {
    subLayout.setVisibility(View.VISIBLE);        
    }
 });

Upvotes: 0

Rotary Heart
Rotary Heart

Reputation: 1969

if I understand you correctly something like this will do the trick:

invite.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        linearlayoutbar1.setVisibility(View.VISIBLE);
        linearlayoutbar2.setVisibility(View.GONE);
    }
});

share.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        linearlayoutbar2.setVisibility(View.VISIBLE);
        linearlayoutbar1.setVisibility(View.GONE);
    }
});

Upvotes: 1

Related Questions