После ListView onClick, измените активность - PullRequest
0 голосов
/ 10 января 2012

Вот мой код

this.getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent i = new Intent(this,lastview.class);    
startActivity(i);
}
});

"this" - это ListActivity, но я хочу, чтобы следующее действие было обычным

и мой код неверен в этой строке

Intent i = new Intent(this,lastview.class);

неверное сообщение:

 The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<lastview>) is undefined

как я могу это исправить?

Ответы [ 3 ]

1 голос
/ 10 января 2012

изменить эту строку

Intent i = new Intent(this,lastview.class); 

вот так, измени свою активность на MyListActivity

Intent i = new Intent( MyListActivity.this, lastview.class); 
0 голосов
/ 10 января 2012

Вот пример кода. Это поможет вам.

public class YourListActivity extends ListActivity {

private Context context;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

 context =this;

  .....
  ......

 this.getListView().setOnItemClickListener(new OnItemClickListener() {
 public void onItemClick(AdapterView<?> a, View v, int position, long id) {
  Intent i = new Intent(context,lastview.class);   
   // else you can use the code like below    
  //Intent i = new Intent(YourListActivity.this ,lastview.class);   

  startActivity(i);
 }
});

}
0 голосов
/ 10 января 2012

Вы также можете написать это как:

startActivity(new Intent(Yourclass_name.this,lastview.class));  
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...