我有2项活动。活动1中有一个可点击的edittext和一个启动浏览器的按钮。活动2具有包含三个项目的列表视图,单击它们并将它们转移到edittext中的活动1。
我需要这样做:运行三个URL中的一个,具体取决于我传递的listview中的哪个值。建议如何正确使用意图并实施if-construction。
活性2
list1 = (ListView) findViewById(R.id.list1);
list1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, s1));
list1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent resultIntent = new Intent();
resultIntent.putExtra("name", s1[position]);
setResult(RESULT_OK, resultIntent);
finish();
public void onClick(View v) {
Intent intent = new Intent(Activity2.this, Activity1.class);
intent.putExtra("name", list1.getOnItemClickListener().toString());
startActivity(intent);
活性1
public static final int REQUEST_LIST = 1;
public void onClick(View v) {
Intent intent = new Intent(this, Activity2.class);
startActivityForResult(intent, REQUEST_LIST);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_LIST:
if (data == null) {
return;
} String name = data.getStringExtra("name");
editText.setText(name);
break;
default:
break;
此处是任务的屏幕截图 - &gt; screenshot