嗨朋友可以帮助我,如何点击另一个按钮后可以看到一个按钮
答案 0 :(得分:0)
试试这个:
buttonONE.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonTWO.setVisibility(View.VISIBLE);
}
});
在布局xml中:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonTWO"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
答案 1 :(得分:0)
像这样:
public class YourClass extends Activity{
Button button1;
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from your xml
setContentView(R.layout.xml_layout_name);
// Locate the buttons in your xml
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
//set listener on button1
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//make button2 visible when button1 is pressed
button2.setVisibility(View.VISIBLE);
}
});
}
}
在xml_layout_name中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:visibility="gone"/>
</RelativeLayout>