问题
I have a program which shows lists of files in directories on the SDCARD and when the user clicks on a file it opens the PDF up. For instance one activity will display the contents of one folder.
I have been wanting to add the ActionBar for navigation and can get the ActionBar to work in its own activity and my ListActivity to work in its own activity, however I cannot get them to work together.
I am not sure how to combine the two so that I end up with one activity that displays the action bar and the file list in the one Activity?
The Actionbar Activity starts with
public class SecondActivity extends FragmentActivity implements ActionBar.OnNavigationListener {
The Activity that displays the clickable list starts with
public class MainActivity extends ListActivity {
My android app programming is quite basic and self taught so I am probably missing something obvious. Thanks in advance
回答1:
I think you can extend your class to ListActivity and override method onCreateOptionsMenu to bind your action bar to the activity:
public class MainActivity extends ListActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.your_action_bar_name_here, menu);
return (super.onCreateOptionsMenu(menu));
}
// your other methods
}
回答2:
I have posted an alternative solution that separates the concerns of the List and the ActionBar. Makes the code a little tidier IMO.
来源:https://stackoverflow.com/questions/13875090/actionbar-and-listactivity-in-one-activity