How to use onCreateOptionsMenu() in Activity Which Extended ListActivity



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://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4" 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)


No comments:

Post a Comment