solved Never mind. It is the onMenuItemSelectedmethod that messed up with the onContextItemSelected method. I am investigating why it screws it up.
solved #2 It appears that both methods are actually same in which onMenuItemSelectedmethod is invoked instead of onContextItemSelected (Hence empty response). I must have misread the google doc :-(
I encounter this strange problem. I have followed the http://developer.android.com/guide/topics/ui/menus.html#context-menu exactly. I already tested it on separate dummy application and it worked fine. The problem is "Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@xxxxxx" whenever I tried to click any context menu item after pressing-and-holding any list item. "onContextItemSelected" method is never called at all time.
Here're the condensed codes:
TaskActivity.java
public class TaskActivity extends Activity{
private ListView task_list;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);//custom xml file of my GUI
task_list = (ListView) findViewById(R.id.listTasks);
populateTaskList();//snapped method
registerForContextMenu(task_list);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
menu.setHeaderTitle("Options");
Log.v("CBC","HERE2");//It logs, yes
}
@Override
public boolean onContextItemSelected(MenuItem item) {
Log.v("CBC","HERE1");//Not ever logged this message!
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.edit_menuitem:
update_task(info.id);
return true;
case R.id.delete_menuitem:
Log.v("CBC","HERE2");
delete_task(info.id);
return true;
}
return super.onContextItemSelected(item);
}
}
<snap irrelevant codes that have played no role in this problem>
activity_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white_bg"
android:orientation="vertical">
<snap irrelvant codes>
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@drawable/list_selectors"
android:id="@+id/listTasks"/>
</LinearLayout>
task_row.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@drawable/row_selector"
android:padding="5dip">
<TextView android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="20dip"/>
<TextView android:id="@+id/mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="20dip"/>
</LinearLayout>
So I am wondering if you have known anything about this such strange problem? Let me know if you need to know more codes else. I assure you they are not relevant.
P.S. This is my big first application written. P.S.S. I just write this little application for my special needs on my Android phone. (Android market free ones are unsuitable to me).