我在尝试从我的 Listview 获取数据时遇到问题,然后在用户从列表中选择产品后在 EditText 中设置该数据字符串。我需要做什么来执行此代码才能实现这一目标?提前致谢。
(另外,对不起,如果这是一个愚蠢的问题,我是 android 和 Java 的新手)
使用 EditText 的活动:
EditText CPU = (EditText) findViewById(R.id.autoCompleteTextView4);
CPU.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent CPUList = new Intent(getApplicationContext(),
CPUList.class);
startActivityForResult(CPUList, RESULT_OK);
}
});
列出活动
final 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<?> myAdapter, View myView, int pos, long mylng) {
String CPU =(listViewCPU.getItemAtPosition(pos).toString());
}
});
}
}