我正在尝试通过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(""));
});
答案 0 :(得分:1)
CPU.setText
不是EditText4
因为你没有真正定义(只要我能看到)
答案 1 :(得分:0)
EditText CPU = ((EditText)findViewById(R.id.EditText4));
你在这一行上缺少一个分号:)
答案 2 :(得分:0)
你这样设置
@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("key", CPU);
startActivity(i);
}
});
获得类似的值
Intent i = getIntent();
String product = i.getStringExtra("key");
EditText CPU = ((EditText)findViewById(R.id.EditText4));
CPU.setText(product);