I have a problem about my android app project.
I have a MainActivity which is below:
public class MainActivity extends ListActivity {
private NotesDataSource datasource;
List<NoteItem> notesList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
datasource = new NotesDataSource(this);
refreshDisplay();
}
private void refreshDisplay() {
notesList = datasource.findAll();
ArrayAdapter<NoteItem> adapter = new ArrayAdapter<NoteItem>(this, R.layout.list_item_layout, notesList);
setListAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
And Also I have a menu_main.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="@+id/action_create"
android:title="@string/action_create"
android:orderInCategory="100"
app:showAsAction="always|withText"
android:icon="@drawable/create_note"/>
</menu>
At this point the problem is starting. I have changed my superclass from ActionBarActivity to ListActivity then, when I run my app on my device, I can not see my create icon (and the top menu which include app name). What's wrong? And idea?
(Btw I am using Android Studio Ide)
Your theme is probably still based on Theme.AppCompat
. If you want to use Theme.AppCompat
, you have to inherit from ActionBarActivity
. If you want to use ListActivity
, you cannot use Theme.AppCompat
.
Note that you do not need to use ListActivity
to have a ListView
in an activity. Here is a sample project demonstrating the use of Theme.AppCompat
with an ActionBarActivity
and a ListView
. Here is another sample project, the same as the previous one, except that I apply custom tints to the action bar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With