1
我有一個listView與一些數據來自server.I想做一個活動,每次我按列表items.any想法之一嗎?listView onclick activity
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);
}
});
,但沒有人方法的工作...請幫助!
好的,我添加的這段代碼正在工作。這會返回我一個敬酒。爲了打開一個新的活動,我必須添加什麼? – 2011-01-27 23:36:10