views:

76

answers:

3

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);
}
A: 

You don't do it that way. See this question and answers.

Qberticus
A: 

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.
BrennaSoft
When I do that, I get this exception: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.android.catsMobile/org.android.catsMobile.EventoSingle}: java.lang.InstantiationException: org.android.catsMobile.EventoSingle
Rafael Carvalho
Post the code for EvenToSingle.
BrennaSoft
A: 

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.

Rafael Carvalho