public class MainActivity extends AppCompatActivity {
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn= (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CityListActivity.startCityActivityForResult(MainActivity.this);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CityListActivity.REQUEST_CODE&&requestCode==CityListActivity.RESULT_CODE){
String cityname=data.getStringExtra(CityListActivity.RESULT_KEY);
btn.setText(cityname);
}
}
}
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn= (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CityListActivity.startCityActivityForResult(MainActivity.this);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CityListActivity.REQUEST_CODE&&requestCode==CityListActivity.RESULT_CODE){
String cityname=data.getStringExtra(CityListActivity.RESULT_KEY);
btn.setText(cityname);
}
}
}