在这里,我在我的项目中创建了 2 个活动。
public class CheckAvailability extends Activity{
Button but1,but2;
EditText brName;
TextView txt1;
String text;
//private static final String ATM_NO = "atmbrno";
//private static final String ATM_PLACE = "atmbrname";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.availability);
brName =(EditText)findViewById(R.id.editText1);
but1 = (Button)findViewById(R.id.button5);
but2 = (Button)findViewById(R.id.button6);
but1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String b_name=brName.getText().toString();
Intent intent1 = new Intent();
intent1.setClass(getApplicationContext(), ListAtmActivity.class);
Bundle b = new Bundle();
b.putString("key", b_name);
intent1.putExtras(b);
startActivity(intent1);
finish();}
});
but2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent1 = new Intent();
intent1.setClass(getApplicationContext(), SelectOption.class);
startActivity(intent1);
} });
}
}
我想将 b_name 字符串值传递给另一个活动。这是我的第二个活动。
public class ListAtmActivity extends ListActivity{
TextView error;
String brName;
// contacts JSONArray
JSONArray contacts = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_main);
Bundle b = getIntent().getExtras();
brName = b.getString("key");
error = (TextView)findViewById(R.id.name);
error.setText(brName);}}
但我无法在我的第二个活动中得到那个字符串?请帮我找出错误?