2014-07-07 25 views

回答

1

你达到“AAA”的EditText的数据后,您可以创建等于什么是在一个的EditText变量。

然后,您可以使用SharedPreferences将变量保存到一个键中,然后在其他活动上使用此键。

创建一个名为a的变量,==您的edittext文本。

然后使用此代码来保存“a”的一个关键:

SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE); 
    score = prefs.getInt("key", a); 

,然后在其他活动中使用此代码来获得“一”:

SharedPreferences prefs = getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE); 
    int value = prefs.getInt("key", 0); 
+0

txtMeja =(EditText)findViewById(R.id.No_Meja); \t \t txtQuota =(EditText)findViewById(R.id.Quota); SharedPreferences prefs = this.getSharedPreferences(“myPrefsKey”,Context.MODE_PRIVATE); \t String score = prefs.getInt(“key”,txtMeja); getInt错误?怎么解决? – user3806892

+0

您需要首先获得一个名为“a”的变量,并使其等于在编辑文本中键入的内容,然后使用我的代码..或者您可以使用其他指示的意图。 – DavidBalas

+0

感谢您的解决方案 – user3806892

0

使用putExtra传递活动之间的争论:

Intent intent = new Intent(this, ccc.class); 
intent.putExtra("EDIT_TEXT_DATA", editText.getText().toString()); 
startActivity(intent) 
+0

但活动AAA到BBB,而BBB至CCC,可以发送从aaa到ccc? – user3806892

+0

然后通过它从aaa到bbb和从bbb到ccc – OferM

+0

如此复杂:D – user3806892

0

可以实现它使用意图,这样做:

Intent intent = new Intent(this, ccc.class); 
intent.putExtra("data from edittext", editText.getText().toString()); 
startActivity(intent); 

然后在ccc类中做到这一点;

Intent intent = getIntent(); 

String dataFromaaa = intent.getStringExtra("data"); 
0

你需要引用您的EditText并获得text:

EditText et = (EditText) findViewById(R.id.my_edit_text); 
String theText = et.getText().toString(); 

然后将它传递到另一个Activity,您使用的Intent。例如:

Intent i = new Intent(this, MyNewActivity.class); 
i.putExtra("text_label", theText); 
startActivity(i); 

在新的活动中(onCreate()),你得到的意向和检索的字符串,例如:

public class MyNewActivity extends Activity { 

    String string1; 

    @Override 
    protected void onCreate(...) { 

     ... 

     Intent i = getIntent(); 
     string1= i.getStringExtra("text_label"); 

    } 
} 
相关问题