jajaja
jajaja

Reputation: 389

ListView Group Position set Intent - Android

I have ListView with 6 items, when I click the items I want to go to different activity using intent. I put intent but it goes to only one activity. I want to set intent in different group position. here is my code.

setContentView(R.layout.main);
    setListAdapter(new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1, items));

    selection = (TextView) findViewById(R.id.selection);
}

public void onListItemClick(ListView parent, View v, int position,long id) {
    super.onListItemClick(parent, v, position, id);

    selection.setText(items[position]);
    Intent hash=new Intent(ListUpdatesActivity.this,Activity2.class);
    startActivity(hash);

}

Upvotes: 0

Views: 281

Answers (1)

KEYSAN
KEYSAN

Reputation: 885

You should be use onItemSelected instead of onClick. here are an example about your question.

Define your activity like that. And do not use onClick. add the following lines to onItemSelectedListener;

selection.setText(items[position]);
Intent hash=new Intent(ListUpdatesActivity.this,Activity2.class);
startActivity(hash);

Upvotes: 1

Related Questions