0
好吧,所以我是编程新手,为了学校项目,我必须在android studio中制作咖啡店应用程序。单击按钮后从另一个活动更改编辑文本
我想知道的是,如何在单击按钮后编辑文本空间以添加关于他们将要购买的项目的文本,但将其放置在另一个活动中。
事情是我想做一种添加到购物车的东西,并在去购物车选项卡后,有一个编辑文本,你会看到多少帐户将是。
任何人都可以帮助我吗?
好吧,所以我是编程新手,为了学校项目,我必须在android studio中制作咖啡店应用程序。单击按钮后从另一个活动更改编辑文本
我想知道的是,如何在单击按钮后编辑文本空间以添加关于他们将要购买的项目的文本,但将其放置在另一个活动中。
事情是我想做一种添加到购物车的东西,并在去购物车选项卡后,有一个编辑文本,你会看到多少帐户将是。
任何人都可以帮助我吗?
您可以使用带编辑文本的警报对话框并使用共享首选项传递值。
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater=MainActivity.this.getLayoutInflater();
//this is what I did to added the layout to the alert dialog
View layout=inflater.inflate(R.layout.editxml,null);
alert.setView(layout);
alert.setTitle("Enter Name");
final EditText usernameInput=(EditText)layout.findViewById(R.id.editText1);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
//do your stuff here
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
editxml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/editText1" />
</LinearLayout>
所以我应该把警报对话框中的类,其中按钮是活动和EditText上的“购物车或结账”选项卡,其中信息显示的活动? –
在按钮的onclicklistener上添加警报对话框。并为警报对话框创建一个带有编辑文本的单独XML文件。 –