I tried to implement a custom menu. I used the answer given in this question. In my code the name is ExpandedMenuItem, but in all the examples it is IconMenuItemView. What is happening there? How can I correct this?
Here is my code.
public class MyActivity extends PreferenceActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.proximity_alert_menu, menu);
getLayoutInflater().setFactory(new Factory() {
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
//if(name.equalsIgnoreCase("com.android.internal.view.menu.MenuItem")) {}
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
TextView tView = (TextView) view;
tView.setTypeface(Config.set_font);
tView.setTextColor(Color.RED);
}
});
return view;
} catch (InflateException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
}
Exception show that
java.lang.ClassCastException:com.android.internal.view.menu.ExpandedMenuView cannot be cast to android.widget.TextView
How can i cast this into TextView?