I have a BaseActivity which has my header:
public class BaseActivity extends Activity
{
@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( BaseActivity.this , ProblemioActivity.class);
BaseActivity.this.startActivity(myIntent);
}
});
questions_header.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent( BaseActivity.this , MyQuestionsActivity.class);
BaseActivity.this.startActivity(myIntent);
}
});
}
}
}
It works when I extend it like this:
public class ProblemActivity extends BaseActivity
but if I have a class which extends a ListActivity, I can not also extend the BaseActivity. Is there a way for me to force the classes that extend ListActivity to also be able to have the header? Right now I make them have the header by extending the BaseActivity, but since some extend ListActivity already, I can’t seem to do it that way.
How can I get around this and make the classes that extend the ListActivity also be able to have the header?
Thanks!
You can make
BaseActivityextend fromListActivity, but this will make all your activities aListActivityand probably will create problems to other activities that aren’t a ListActivity.ListActivityisn’t required to useListView. You can useListViewin plain activities. If you want to continue using a BaseActivity for all your activities, then don’t use ListActivity and manage ListView by yourself. Another alternative would be to make your ownListActivitythat extends fromBaseActivity. Here’s a basic example of this: