Akh*_*war 1 android android-edittext android-activity
我在这里看了一下堆栈溢出的例子.但是,我无法获得正常工作的解决方案.我的应用程序仍然崩溃.如何将字符串从一个活动中的编辑文本传递到另一个活动?
这是我第一个活动的代码:
Button btnGo = (Button) findViewById(R.id.btnGo);
btnGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText etLocation = (EditText) findViewById(R.id.et_location);
Intent intent = new Intent();
intent.putExtra("location", etLocation.getText().toString());
startActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
第二活动代码:
textView1 = (TextView) findViewById(R.id.textView1);
Intent intent = getIntent();
String str = intent.getStringExtra("location");
textView1.setText(str);
Run Code Online (Sandbox Code Playgroud)
更改:
Intent intent = new Intent();
Run Code Online (Sandbox Code Playgroud)
至:
Intent intent = new Intent(MyCurrentActivityClass.this, NextActivity.class);
Run Code Online (Sandbox Code Playgroud)
确保NextActivity在Manifest中.在第一种情况下,您没有提供足够的信息来启动活动.
| 归档时间: |
|
| 查看次数: |
33880 次 |
| 最近记录: |