【发布时间】:2018-04-22 16:46:52
【问题描述】:
在这个程序中,我想在按下 mButton 时删除 ll2 (LinearLayout)。即我不希望此布局在我第二次进入此活动时出现。当我按下按钮时,只要我在活动中,布局就消失了,但是当我回到活动中时,布局就在那里。
如何永久删除它?提前致谢!
LinearLayout ll,ll2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
location_btn = (Button)findViewById(R.id.location_btn);
menu_btn = (Button)findViewById(R.id.bt_menu);
mButton = (Button) findViewById(R.id.buttone);
mEdit = (EditText) findViewById(R.id.edittexte);
ll2 = (LinearLayout)findViewById(R.id.llayout);
mButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
number = mEdit.getText().toString();
mEdit.setText("");
ll2.setVisibility(View.GONE);
ll2.removeAllViewsInLayout();
}
});
}
我的布局文件
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/llayout"
android:visibility="visible">
<EditText
android:id="@+id/edittexte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SAVE"
android:id="@+id/buttone"/>
</LinearLayout>
【问题讨论】:
标签: java android android-layout android-linearlayout