我有一个listView,其中包含一些来自服务器的数据。每次按下其中一个列表项时,我都想进行一项活动。有什么想法吗?
public void Status1() {
setContentView(R.layout.status);
update = (Button) findViewById(R.id.update);
refresh = (Button) findViewById(R.id.refresh);
update.setOnClickListener(update_btn);
refresh.setOnClickListener(refresh_btn);
lv1 = (ListView) findViewById(R.id.ListView);
// By using setAdpater method in listview we an add string array in
// list.
lv1.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, lv_arr));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
final EditText username2 = (EditText) findViewById(R.id.username1);
//String a = username1.getText().toString();
//username2.setText(a);
username2.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
// Editable a=findViewById(R.id.username).getText();
// username2.setText(a);
Toast.makeText(yassou.this, username2.getText(),
Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
}
我试过这个:EDIT1
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
startActivity(new Intent("com.example.HelloGoogleMaps2"));
}
});
和这:EDIT2
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Intent myIntent = new Intent(view.getContext(), HelloGoogleMaps2.class);
startActivityForResult(myIntent, 0);
}
});
但没有人使用方法......请帮助!!
答案 0 :(得分:0)
您可以附加intent和bundle作为listview的适配器的一部分。这会将适当的包传递给用户单击列表项时启动的活动。