一旦用户从我的 ListView 中选择了一个产品,它就会将该 ListView 中的选定文本放入 EditText。我遇到的问题是当用户从列表中选择一个产品,然后按回时,它再次出现列表而不是返回到 EditText 活动。
我试过使用“finish();” 活动开始后,但似乎没有任何效果。
包含启动 List 活动的 EditText 的活动:
EditText CPU = (EditText) findViewById(R.id.autoCompleteTextView4);
CPU.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent CPUList = new Intent(getApplicationContext(),
CPUList.class);
startActivityForResult(CPUList, 1);
Intent i = getIntent();
String product = i.getStringExtra("key");
EditText CPU = ((EditText) findViewById(R.id.autoCompleteTextView4));
CPU.setText(product);
}
});
列表视图类
@Override
public void onCreate(Bundle OnsaveInstanceState) {
super.onCreate(OnsaveInstanceState);
setContentView(R.layout.activity_cpulist);
ListView listViewCPU = (ListView) findViewById(R.id.listViewCPU);
listViewCPU.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
String CPUList[] = {
"CPU's go here", "CPU's go here", "CPU's go here", "CPU's go here" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, CPUList);
listViewCPU.setAdapter(adapter);
listViewCPU.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listview, View myView,
int pos, long mylng) {
String CPU = (String) listview.getAdapter().getItem(pos);
Intent i = new Intent();
i.putExtra("key", CPU);
setResult(1, i);
finish();
}
});