窗口已經集中,忽略了聚焦增益:com.android.internal.view.IInputMethodClient $存根$代理@ 43882778
這裏是大多數Main類的代碼,其中onMenuClick被忽略。
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.class);
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"));
}
}
}
}
最初我的CategoryEdit.class沒有在AndroidManifest.xml文件中列出。我已將其添加到清單並仍然收到相同的錯誤。
就是這樣!非常感謝你。我不確定onOptionsItemSelected或onMenuItemSelected之間有什麼不同,但我會做一些研究並找出答案。再次感謝您的幫助。 – alockrem 2010-08-27 17:51:17