我正在尝试通过 ListView 设置 EditText 的文本。一旦用户从 ListView 中选择了一个产品,它将返回到保存 EditText 的活动,并更改 EditText 中的文本。
我对 Android 和 Java 比较陌生,所以请原谅我是一个绝对的小人物。
列出 Java:
final ListView listViewCPU = (ListView) findViewById(R.id.listViewCPU);
listViewCPU.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
String CPUList[] = {
"Products go here", "Products go here", "Products go here", "Products go here", "Products go here", "Products 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(getApplicationContext(), ListmenuActivity.class);
i.putExtra(" ", CPU);
startActivity(i);
}
});
}
}
EditText Java:我在“EditText4”上收到错误,定义“令牌“EditText4”上的语法错误,删除此令牌”
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, 0);
}
Intent i = getIntent();
String product = i.getStringExtra(" ");
EditText CPU = ((EditText)findViewById(R.id.EditText4));
EditText4.setText(getIntent(i).getStringExtra(""));
});