Questo è il mio file xml per il menu ActionBar.findViewById per MenuItem restituisce null
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/fav_button"
android:title="Favourite"
android:icon="@drawable/unstar"
android:showAsAction="always|withText" />
</menu>
Nella mia funzione onCreate
, dopo chiamare setContentView
. Lo faccio favButton = (MenuItem) this.findViewById(R.id.fav_button);
Ma questo restituisce null.
Ma restituisce l'oggetto corretto sulla funzione onOptionsItemSelected
.
Sto usando ActionBarSherlock, se questo avrebbe fatto la differenza.
Ho provato varie opzioni suggerite da altri findViewById restituisce domande nulle, ma non hanno risolto il mio problema.
http://www.vogella.com/articles/AndroidActionBar/article.html. controlla il link – Raghunandan