Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 试图完成输入事件,但已释放输入事件接收器_Android_Listview_Popupmenu - Fatal编程技术网

Android 试图完成输入事件,但已释放输入事件接收器

Android 试图完成输入事件,但已释放输入事件接收器,android,listview,popupmenu,Android,Listview,Popupmenu,我有一个自定义的listview适配器。适配器包含一个文本视图和一个图像按钮。我在点击图像按钮时实现了一个弹出菜单。一切正常。但是,当从弹出菜单中选择选项时,logcat显示一条单行消息“试图完成输入事件,但输入事件接收器已被释放”,并且没有发生任何事情 public class MyAdapter extends ArrayAdapter<String> { public MyAdapter(Context context, int resourceId) {

我有一个自定义的listview适配器。适配器包含一个文本视图和一个图像按钮。我在点击图像按钮时实现了一个弹出菜单。一切正常。但是,当从弹出菜单中选择选项时,logcat显示一条单行消息“试图完成输入事件,但输入事件接收器已被释放”,并且没有发生任何事情

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;
    }
}
我从消息中了解到,在onMenuItemClick()执行之前,有东西正在吞噬事件。我正在Nexus5Android 5.0.1上运行我的应用程序

我从中找到了类似问题的解决方案。但我不知道如何用这种方法解决我的问题

我尝试使用上下文菜单而不是弹出菜单,但在单击上下文菜单项后仍然出现相同的消息“试图完成输入事件,但输入事件接收器已被释放”


请帮帮我

我从另一个角度探讨了这个问题;正在尝试从菜单启动服务。默认情况下,调试消息不太相关。我的解决方案是消除logcat中的过滤器,然后我收到另一条消息,它首先无法启动服务(我忘记将其放在清单文件中)

在您的情况下,可能需要将toast显示包装到一个类中:

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.postdayed()
方法


HTH,

您必须在super()中传递R.layout.id以防止此错误。 例如:

public PersonAdapter(Context c, ArrayList<String> list) {
            super(c, R.layout.item_layout, list);
}
publicpersonadapter(上下文c,数组列表){
超级(c、R.布局图、项目/布局图、列表);
}

我在以下场景中收到此错误消息:活动创建对话框。该对话框被分配了一个KeyListener。按下后退按钮,活动+对话框关闭。显然,对话框在“输入事件”结束前关闭。如何“在logcat中消除过滤器”?@Kidburla,在AS中,在“Android监视器”上,选择“无过滤器”而不是“仅显示选定的应用程序”。
public PersonAdapter(Context c, ArrayList<String> list) {
            super(c, R.layout.item_layout, list);
}