Hi
I am new in android.
I have many Buttons
in view in android and i want to show them part by part by clicking another button.
Hi
I am new in android.
I have many Buttons
in view in android and i want to show them part by part by clicking another button.
Set button visibility to GONE (button will be completely "removed" -- the buttons space will be available for another widgets) or INVISIBLE (button will became "transparent" -- its space will not be available for another widgets):
View b = findViewById(R.id.button);
b.setVisibility(View.GONE);
or in xml:
<Button ... android:visibility="gone"/>
Ref By: LINK
use android:visibility="visible"
or android:visibility="gone"
or android:visibility="invisible"
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="91dp"
android:layout_toLeftOf="@+id/textView1"
android:text="Button"
android:visibility="visible" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_alignLeft="@+id/textView1"
android:text="Button"
android:visibility="invisible" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:text="Button"
android:visibility="invisible" />
let say you have 2 buttons : in xml write this:Make button 2 invisible like below
<Button android:id="@+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button android:id="@+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="button 2"
android:layout_below="@+id/btn1"
android:visibility="invisible"/>
In your oncreate method write this: when you click on button1 , button2 will appear.
Button btn1 = (Button)findViewById(R.id.btn1);
final Button btn2 = (Button)findViewById(R.id.btn2);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
btn2.setVisibility(View.VISIBLE);
}
});
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="91dp"
android:layout_toLeftOf="@+id/textView1"
android:text="Button"
android:visibility="gone" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_alignLeft="@+id/textView1"
android:text="Button"
android:visibility="gone" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:text="Button"
android:visibility="gone" />
Now in your code on click event just set the visibility of these buttons to VISIBLE.
Steps for changing the visibility HashMap map=new HashMap(); map.put(R.id.button1,new Integer[]{R.id.button2,R.id.button3,R.id.button4});
public void onClick(View v){
Integer[] buttonsToShow=map.get(R.id.v.getId());
if(buttonsToShow!=null) for(int button:buttonsToShow){
findViewById(button).setVisibility(View.VISIBLE);
} }
I wrote following code and solved my problem. maybe it might be useful to anyone next = (Button)findViewById(R.id.next); next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
if(i<movie_list.length-3)
{
movie_list[i].setVisibility(View.GONE);
movie_list[i+3].setVisibility(View.VISIBLE);
i++;
}else{
Toast.makeText(getApplicationContext(), "That is the end of the buttons ", Toast.LENGTH_SHORT).show();
}
}
});