I want to make all my list items in the listview open up into a new page, so each listview item opens up onto a new black page that I can use. I don’t know how to implement this at all. I have searched for hours on end and can’t find an answer to my solution. It would be much appreciated if someone could show and/or explain how to do this instead of providing a link, but either is helpful.
Here is my code so far:
<string-array name="sections">
<item >Pro Constructive</item>
<item >Con Constructive</item>
<item >1st Speaker Cross</item>
<item >Pro Rebbutal</item>
<item >Con Rebuttal</item>
<item >2nd Speaker Cross</item>
<item >Pro Summary</item>
<item >Con Summary</item>
<item >Grand Cross</item>
<item >Pro Final Focus</item>
<item >Con Final Focus</item>
</string-array>
This is in my string.xml
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:entries="@array/sections" >
</ListView>
This is in my activity_main.xml.
Where do I go from here to make each item in my list clickable and able to open up onto a new page?
Thanks in advance!
EDIT:
Logcat no longer relevant.
In fact it is quite easy:
This is your Activity with the ListView, it implements an OnItemClickListener:
Edit
The above code would be placed in your MainActivity.java. I changed the name of the class to
MainActivityand the contentView tosetContentView(R.layout.activity_main)– The names are those of a freshly created Android Project in Eclipse.Please see also the 2 new lines under //* Edit * – those will set the Listener for clicks on items in the list.
Your activity_main.xml should look like this:
The array.xml (not string.xml) in your `res/values/` folder looks like this
N.B.: If you copy & paste this code it should work. But you will get an error by clicking on an Item because you haven’t created the
ListItemDetail.classyet.Here is an example of how this could look:
Your ListItemDetail.java:
And its activity_listitem.xml
If you copy past this code it will work.