I have a list view with 15 items. When I click on any item I want to change the screen(Intent). how can I change the activity on item selected in android? any tutorial or source code?
2
-
1What part are you having trouble with? Knowing a click occurred, determining which item was clicked, or starting a new activity?Mark B– Mark B2010-10-08 11:33:40 +00:00Commented Oct 8, 2010 at 11:33
-
2please, do a little bit of research yourself before asking a question. This same question (both the item clicked and the change activity) is answered more than 10 times just in SO.Maragues– Maragues2010-10-08 11:41:05 +00:00Commented Oct 8, 2010 at 11:41
Add a comment
|
3 Answers
You can use ListView's setOnItemClickListener, and start an new Activity in your implementation of this method. Following is sample code:
myListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id){
// Start your Activity according to the item just clicked.
}
});
Comments
final ListView list = (ListView) findViewById(R.id.SCHEDULE);
protected void onCreate(Bundle savedInstanceState) {
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
Toast.makeText(getApplicationContext(),"hiihih",Toast.LENGTH_SHORT).show();
}
});
}
Comments
Check the selected answer in ListView OnItemClickListener Not Responding?
If you also need code examples to change activity, head to https://developer.android.com/guide/index.html and start reading.
// Prepare intent
Intent newActivity = new Intent(this, NewActivity.class);
// start activity
startActivity(newActivity);