试图完成一个输入事件,但输入事件接收器已被释放 [英] Attempted to finish an input event but input event receiver has already been disposed
问题描述
我有我的列表视图自定义适配器。该适配器包含一个TextView和一个图像按钮。我已经实现在点击图像按钮的弹出式菜单。一切工作正常。但选择的选项,从弹出菜单中,显示的logcat一行消息时试图完成一个输入事件,但输入事件接收器已被释放,并没有什么发生。
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接口
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();
}
}
我从消息理解的是,有些事情是吃onMenuItemClick之前的事件()被执行。我的关系运行我的应用程序5款Android 5.0.1。
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.
请帮我... !!
推荐答案
我已经打从另一个角度这个问题;试图从菜单中启动的服务。缺省情况下,调试消息是不是太重要。我的解决办法是消除logcat的过滤器,然后我得到了另一个消息,它无法启动的第一个服务到位(我忘了把它放在我的manifest文件)。
I've hit this problem from another angle; trying to launch a service from a menu. By default, the debug message is not too relevant. My solution was to eliminate filters in logcat and then I got another message that it could not launch the service in the first place (I forgot to put it in my manifest file).
在你的情况,你可能需要包装敬酒显示成一个类:
In your case, you may need to wrap the toast display into a class:
public class DisplayToast implements Runnable {
private final Context mContext;
private final String mText;
public DisplayToast(Context mContext, String text) {
this.mContext = mContext;
mText = text;
}
public void run() {
Toast.makeText(mContext, mText, Toast.LENGTH_SHORT).show();
}
}
和通过处理程序
对象调用它:
mHandler.post(new DisplayToast(this, "Epic message!"));
,或者甚至更好,使用 Handler.postDelayed()
方法。
心连心,
这篇关于试图完成一个输入事件,但输入事件接收器已被释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!