I had a list with one column which worked with an adapter, and it worked. Now I am trying to make it into two columns, and I am getting exceptions.
I am following this tutorial which seems to be the simplest: http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/
I have a Java Activity that I declare like this:
public class SeeAllQuestionsActivity extends ListActivity
and here is a bit of code:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
FlurryAgent.onStartSession(this, "8CA5LTZ5M73EG8R35SXG");
setContentView(R.layout.all_question_page);
...
Here is the all_question_page xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3px"
>
<include android:id="@+id/header"
layout="@layout/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<TextView
android:id="@+id/loading_questions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some prompt text."
android:textSize="10sp"
/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@+id/label"
android:textSize="20px" >
</ListView>
</LinearLayout>
By the way, if someone can explain to me the diffrence between two syntaxes for referencing the list id, it would be great:
android:id="@android:id/list"
android:id="@+id/list"
FYI, neither of these is working for me 🙂
And here is the questions_list.xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/TRAIN_CELL"
android:layout_width="50dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/FROM_CELL"
android:layout_width="70dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="@+id/TO_CELL"
android:layout_width="60dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>
When I run this on the simulator, it crashes with a runtime exception complaining about this line: setContentView(R.layout.all_question_page); and the error is:
java.lang.RuntimeException:
Your content must have a ListView whose id attribute is 'android.R.id.list'
Please help, I am pretty stuck
Thank you!!
The difference seems to be that the former is what you’d need to use in order to use a ListActivity and the latter is what you’d use if you weren’t going to use ListActivity, but instead just a normal Activity. So you’ll have to stick with. (Note: I’ve never personally used ListActivity, so I can’t exactly vouch for this)
I would also suggest removing these too lines from your ListView:
Neither text, nor textSize are valid attributes of ListView. And for any widget that text is a valid attribute of I don’t think you’d ever want to set the text equal to something like
"@+id/label". If you are trying to reference a string from your strings.xml file you’d need to use"@string/label". Referencing an id like that for the text will put some hex code into the text that will have no meaning to the user(if it works at all).It is possible that removing those might fix your trouble, if so my guess is that having the text set to another id was confusing something into thinking that your list didn’t have the id
listIf that does not solve your problem I would suggest switching to a plain Activity instead of ListActivity and getting the reference to your ListView via
findViewById()like they do in the example that you linked.