I'm developing a android application that uses a ListActivity.
In the method onListItemClick, I instantiate an object x. I have an Activity a whose constructor receives and object of the same type of x. How do I do to instantiate a and start it?
Pretty much like this, but it does not work:
protected void onListItemClick(ListView l, View v, int position, long id) {
EventoSingle eventoSingle = new EventoSingle(this.eventos.get(position));
Intent i = new Intent(this, EventoSingle.class);
eventoSingle.startActivity(i);
startActivity(i);
super.onListItemClick(l, v, position, id);
}
You don't do it that way. See this question and answers.
No you are doing it incorrectly.
You need to do it like this.
Intent i = new Intent(this, EvenToSingle.class);
i.putExtra("somekey", this.eventos.get(position)); // this will depend on the type of extra
startActivity(i);
And then in your onCreate for the new Activity.
Intent i = getIntent();
obj = i.getExtra("somekey"); // this will depend on the type of Extra.
The problem was solved using what people told me to do in the answers. But then another error occurred:
"newInstance failed: no ()"
Then I checked this question/answer and everything is working just fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.