When I click on a menu item I am presented with the following message in DDMS:
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43882778
Here is most of the code from the Main class where the onMenuClick is being ignored.
public class Main extends TabActivity {
public static final int ACTIVITY_CREATE = 0;
private static final int ADD_ID = Menu.FIRST;
private Long listId;
private DbHelper mDbHelper;
private Cursor mCursor;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set the list id
Bundle extras = getIntent().getExtras();
if (extras != null) {
listId = extras.getLong("listId");
}
// Open the database
mDbHelper = new DbHelper(this);
mDbHelper.open();
// Setup the tabs
createTabs();
}
public void createTabs() {
mCursor = mDbHelper.fetchAllCategories(listId);
startManagingCursor(mCursor);
for (int i = 0; i [less than symbol] mCursor.getCount(); i++)
{
createTab(
mCursor.getLong(mCursor.getColumnIndexOrThrow("_id")),
mCursor.getString(mCursor.getColumnIndexOrThrow("category")));
}
}
public void createTab(Long categoryId, String category) {
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent();
intent.putExtra("Test", category);
intent.setClass(this, Categories.class);
spec = tabHost.newTabSpec(category);
spec.setContent(intent);
spec.setIndicator(category);
tabHost.addTab(spec);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, ADD_ID, 0, R.string.menu_addCategory).setIcon(R.drawable.add_grey);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case ADD_ID:
addCategory();
return true;
}
return super.onMenuItemSelected(featureId, item);
}
public void addCategory() {
Intent intent = new Intent();
intent.setClass(this, CategoryEdit.cl开发者_StackOverflow中文版ass);
startActivityForResult(intent, ACTIVITY_CREATE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case ACTIVITY_CREATE:
if (resultCode == RESULT_OK) {
Bundle createExtras = intent.getExtras();
mDbHelper.addCategory(createExtras.getString("category"));
}
}
}
}
Originally my CategoryEdit.class wasn't listed in the AndroidManifest.xml file. I have added that to the manifest and still receive the same error.
use ::
public boolean onOptionsItemSelected(MenuItem item) {
instead of::
public boolean onMenuItemSelected(int featureId, MenuItem item) {
Try changing it to intent.setClass(TabActivity.this, CategoryEdit.class);
If that doesn't work I'm gonna need some more output from Logcat, you can one line and it is really helping much.
精彩评论