嗨,大家好我是Android工作室的初学者,我想在按钮点击后在Android上做按钮功能 我试过打电话finish();
,但它没有工作,导致它删除变量我已经在我的第一个活动触发Android按钮点击后退按钮功能
那是我第一次activiy(Mou3adal)代码:
final Button m1 = (Button) findViewById(R.id.m1);
m1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Mou3adal.this, Arabic.class));
}
});
try {
Bundle bundleba = getIntent().getExtras();
double t1V = bundleba.getDouble("t1V");
double f1_1V = bundleba.getDouble("f1_1V");
double f2_1V = bundleba.getDouble("f2_1V");
double i1V = bundleba.getDouble("i1V");
double mou1V = bundleba.getDouble("mou1V");
m1.setTextSize(15);
m1.setText(" ت:" + t1V + " ف:" + f1_1V + " ف:" + f2_1V + " إ:" + i1V + " م:" + mou1V);
} catch (Exception e) {
m1.setTextSize(25);
m1.setText(" إضغط لكتابة نقاطك");
}
final Button m2 = (Button) findViewById(R.id.m2);
m2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Mou3adal.this, francais.class));
}
});
try {
Bundle bundlebf = getIntent().getExtras();
double t2V = bundlebf.getDouble("t2V");
double f1_2V = bundlebf.getDouble("f1_2V");
double f2_2V = bundlebf.getDouble("f2_2V");
double i2V = bundlebf.getDouble("i2V");
double mou2V = bundlebf.getDouble("mou2V");
m2.setTextSize(15);
m2.setText(" ت:" + t2V + " ف:" + f1_2V + " ف:" + f2_2V + " إ:" + i2V + " م:" + mou2V);
} catch (Exception e) {
m2.setTextSize(25);
m2.setText(" إضغط لكتابة نقاطك");
}
这就是我的第二个活动(阿拉伯语)代码:
Button OK1 = (Button)findViewById(R.id.OK1);
OK1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (t1.getText().toString().isEmpty()) {
Toast.makeText(Arabic.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (f1_1.getText().toString().isEmpty()) {
Toast.makeText(Arabic.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (f2_1.getText().toString().isEmpty()) {
Toast.makeText(Arabic.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (i1.getText().toString().isEmpty()) {
Toast.makeText(Arabic.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (mou1.getText().toString().isEmpty()) {
Toast.makeText(Arabic.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else {
double t1V = Double.parseDouble(t1.getText().toString());
double f1_1V = Double.parseDouble(f1_1.getText().toString());
double f2_1V = Double.parseDouble(f2_1.getText().toString());
double i1V = Double.parseDouble(i1.getText().toString());
double mou1V = Double.parseDouble(mou1.getText().toString());
Intent PasseData_Intent = new Intent(Arabic.this,Mou3adal.class);
Bundle bundleba= new Bundle();
bundleba.putDouble("t1V",t1V);
bundleba.putDouble("f1_1V",f1_1V);
bundleba.putDouble("f2_1V",f2_1V);
bundleba.putDouble("i1V",i1V);
bundleba.putDouble("mou1V",mou1V);
PasseData_Intent.putExtras(bundleba);
startActivity(PasseData_Intent);
finish();
}
}
});
这就是我的第三个活动(Francais)代码: final EditText t2 =(EditText)findViewById(R.id.t2);
final EditText f1_2 = (EditText) findViewById(R.id.f1_2);
final EditText f2_2 = (EditText) findViewById(R.id.f2_2);
final EditText i2 = (EditText) findViewById(R.id.i2);
final EditText mou2 = (EditText) findViewById(R.id.mou2);
Button OK2 = (Button)findViewById(R.id.OK2);
OK2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (t2.getText().toString().isEmpty()) {
Toast.makeText(francais.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (f1_2.getText().toString().isEmpty()) {
Toast.makeText(francais.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (f2_2.getText().toString().isEmpty()) {
Toast.makeText(francais.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (i2.getText().toString().isEmpty()) {
Toast.makeText(francais.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else if (mou2.getText().toString().isEmpty()) {
Toast.makeText(francais.this, "يرجى ملئ جميع الفراغات ", Toast.LENGTH_SHORT).show();
} else {
double t2V = Double.parseDouble(t2.getText().toString());
double f1_2V = Double.parseDouble(f1_2.getText().toString());
double f2_2V = Double.parseDouble(f2_2.getText().toString());
double i2V = Double.parseDouble(i2.getText().toString());
double mou2V = Double.parseDouble(mou2.getText().toString());
Intent PasseData_Intent2 = new Intent(francais.this, Mou3adal.class);
Bundle bundlebf = new Bundle();
bundlebf.putDouble("t2V", t2V);
bundlebf.putDouble("f1_2V", f1_2V);
bundlebf.putDouble("f2_2V", f2_2V);
bundlebf.putDouble("i2V", i2V);
bundlebf.putDouble("mou2V", mou2V);
PasseData_Intent2.putExtras(bundlebf);
startActivity(PasseData_Intent2);
finish();
}
}
});
}}
你可以做dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_BACK)); –
完成应该先来,然后你必须启动Mou3adal活动 –
我会试试这个 –