Note that there are some explanatory texts on larger screens.

plurals
  1. POarray that starts a new activity
    text
    copied!<p>OK, I realize this is prolly pretty basic, but im so new to this its unreal.</p> <p>What I have is an array. What I want is for when a user clicks an item in the array, it opens a new activity that is specific to that item. Its a list of festivals, and when you click on one of the festivals, and when you click on it, it opens an activity that provides information about that festival.</p> <p>I have no idea what I'm doing here. Im pretty sure I need to use an OnClickListener, but thats it.</p> <p>Activity</p> <pre><code> package com.MADONK.LAFESTS; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import android.widget.TextView; public class Home extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.main, Festivals)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); } static final String[] Festivals = new String[] { "Lake Arthur Regatta", "Contraband Days", "Iowa Rabbit Festival", }; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload