I have some classes that used to inherit from ListActivity directly. Everything worked. Now I am inheriting from BaseListActivity which inherits from ListActivity.
Here is BaseListActivity:
public class BaseListActivity extends ListActivity
{
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
{
Button home_header = (Button)findViewById(R.id.home_header);
Button questions_header = (Button)findViewById(R.id.questions_header);
home_header.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent( BaseListActivity.this , ProblemioActivity.class);
BaseListActivity.this.startActivity(myIntent);
}
});
questions_header.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent( BaseListActivity.this , MyQuestionsActivity.class);
BaseListActivity.this.startActivity(myIntent);
}
});
}
}
It basically adds a header to the page. But now none of the lists get rendered and there are no exceptions.
Any idea what else I had to do to make it work?
Here is how I changed my original layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include android:id="@+id/header"
layout="@layout/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<TextView
android:id="@+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading your questions..."
/>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="20px" >
</ListView>
Here is my onCreate
public class MyQuestionsActivity extends BaseListActivity
{
ArrayAdapter<Question> adapter;
ArrayList<Question> questions = new ArrayList <Question>( );
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.users_questions);
Question q = new Question ();
q.setQuestion( "" );
questions.add(q);
adapter = new ArrayAdapter<Question>(this, R.layout.user_question_list, questions);
Right now I have this in my BaseListActivity
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
{
I just tried this:
public class BaseListActivity extends ListActivity
{
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
{
setListAdapter(this.getListAdapter());
but it didn’t quite work 🙁
Please see this
http://jnastase.alner.net/archive/2011/08/08/custom-android-listactivity.aspx
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
is there this line in onCreate ………
setContentView(R.layout.main);