I have a custom adapter for my listview. The adapter contains a textview and a image button. I have implemented a popup menu on clicking the image button. Everything is working fine. But when selecting the options from popup menu, logcat displaying a single line message "Attempted to finish an input event but input event receiver has already been disposed" and nothing is happening.
public class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resourceId) {
super(context, resourceId);
}
public MyAdapter(Context context, int resourceId, List<String> string) {
super(context, resourceId, string);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
v = inflater.inflate(R.layout.adapter_layout, null);
}
String str = getItem(position);
if(str != null) {
TextView textView = (TextView)v.findViewById(R.id.editText1);
textView.setText(str);
ImageButton button = (ImageButton)v.findViewById(R.id.imageButton1);
button.setOnClickListener(new Custom_Adapter_Button_Click_Listener(getItemId(position), getContext()));
}
return v;
}
}
onclicklistener interface is
public class Custom_Adapter_Button_Click_Listener implements OnClickListener, OnMenuItemClickListener {
long position;
Context context;
public Custom_Adapter_Button_Click_Listener(long id, Context appcontext) {
position = id;
context = appcontext;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
int index = info.position;
Log.d("ItemClicked", "selected index : " + index);
switch(item.getItemId()) {
case R.id.option :
Toast.makeText(context, "Selected index : " + index, Toast.LENGTH_SHORT).show();
return true;
default :
Toast.makeText(context, "Default", Toast.LENGTH_SHORT).show();
return false;
}
}
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(context, v);
MenuInflater popupInflater = popup.getMenuInflater();
popupInflater.inflate(R.menu.contextmenu, popup.getMenu());
popup.show();
}
}
What I understood from the message is that some thing is eating the event before onMenuItemClick() gets execute. I am running my app on nexus 5 android 5.0.1.
I find a solution for similar kind of problem from here. But I am not getting how to use this approach to my problem.
I tried using context menu instead of popup menu, but still I had the same message "Attempted to finish an input event but input event receiver has already been disposed" after clicking on the context menu item.
Please help me...!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…