gpt4 book ai didi

android - 传输 5 个 Activity 页面的数据 26 个编辑文本字段并在最后一个 android Activity 中计算

转载 作者:行者123 更新时间:2023-11-30 03:23:50 25 4
gpt4 key购买 nike

到目前为止,我的问题与 android 应用程序有关,我能够创建 5 个不同的 Activity ,其中包含变量和 onclick 按钮以传递下一个 Activity ...

    public class Abc extends Activity{
Button one2five;
EditText edtA, edtB, edtC, edtD, edtE, edtF;
String tA, tB, tC, tD, tE, tF;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.abc);
one2five = (Button) findViewById(R.id.btp1);
edtA = (EditText) findViewById(R.id.etA);
tA = edtA.getText().toString();
edtB = (EditText) findViewById(R.id.etB);
tB = edtB.getText().toString();
edtC = (EditText) findViewById(R.id.etC);
tC = edtC.getText().toString();
edtD = (EditText) findViewById(R.id.etD);
tD = edtD.getText().toString();
edtE = (EditText) findViewById(R.id.etE);
tE = edtE.getText().toString();
edtF = (EditText) findViewById(R.id.etF);
tF = edtF.getText().toString();
one2five.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent openg2j = new Intent("com.sport.sport.G2J");
startActivity(openg2j);
}
});

}
}

现在以此为基础,我又创建了 4 个页面,总共有 26 个不同的编辑文本字段。

我的目标是:-在一个计算页面中获取所有编辑文本。执行计算并将结果发布在一页上。

问题:-获取用户文本所有十进制数字如果一个字段留空并突出显示,用户会得到提示。如果用户按下返回,之前的 Activity 应该已经输入了值。

谁能帮我解决这个问题..谢谢莫妮卡

最佳答案

如果您想在整个应用程序中保存数据,请使用“SHARED PEFERENCES”

保存值:

    SharedPreferences preferences = getSharedPreferences("MY_SHARED_PREF",0);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt(String.valueOf(key), value);//store int values, can use string,arrays,etc
editor.commit();

加载保存的值:

        SharedPreferences getProgramPrefs = this.getSharedPreferences(
"MY_SHARED_PREF", MODE_WORLD_READABLE);

int Index = getProgramPrefs.getInt(String.valueOf(key), -1);

对于这个“用户按回之前的 Activity 应该之前输入的值”,您可以尝试使用 finish() 或加载首选项值

                         finish();

关于android - 传输 5 个 Activity 页面的数据 26 个编辑文本字段并在最后一个 android Activity 中计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18610929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com