1

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);
}
rlc
  • 4,921
  • 5
  • 36
  • 46

3 Answers3

0

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

Community
  • 1
  • 1
Rich Schuler
  • 40,748
  • 6
  • 68
  • 58
0

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.
Robby Pond
  • 70,876
  • 16
  • 121
  • 117
  • 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 – rlc Jul 01 '10 at 22:23
0

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.

Community
  • 1
  • 1
rlc
  • 4,921
  • 5
  • 36
  • 46