Combining Listactivity And Actionbaractivity
I am currently building for a minimum SDK of 10, so I have to use the android-support-v7-appcompat library to implement ActionBar. I have setup the ActionBar, but I want to now add
Solution 1:
ListActivity hasn't been ported to AppCompat. Probably because you should consider it 'deprecated', and instead use a ListFragment.
Fragments will work with a ActionBarActivity, just make sure they are fragments from the support library.
Have a read through this link about fragments.
For your use case, I would just define the fragment in xml.
Solution 2:
The easiest way to do this is to use a ListFragment
inside of the ActionBarActivity
. I did it like this:
publicclassMyActivityextendsActionBarActivity {
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
MyFragmentfragment=newMyFragment();
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
}
publicbooleanonOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
finish();
break;
}
default: {
break;
}
}
returntrue;
}
publicstaticclassMyFragmentextendsListFragment {
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
}
publicvoidonListItemClick(ListView listView, View view, int position, long id) {
...
}
}
}
This way you don't even need an xml for it, and it works well.
Post a Comment for "Combining Listactivity And Actionbaractivity"