Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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_Arraylist_Popupwindow - Fatal编程技术网

Android:弹出窗口:试图完成输入事件,但输入事件接收器已被释放

Android:弹出窗口:试图完成输入事件,但输入事件接收器已被释放,android,arraylist,popupwindow,Android,Arraylist,Popupwindow,我想在用户按下分类按钮时添加一个弹出窗口。该窗口将显示可用类别的列表。弹出窗口的相关代码如下所示: onCreate: 弹出窗口: public-PopupWindow-ppoppupwindowdogs() { 最终PopupWindow localPopupWindow=新PopupWindow(此); ListView lv=新的ListView(本); lv.setAdapter(新的MyCustomArrayAdapter_POP(DB_Ex_ListActivity.this));

我想在用户按下分类按钮时添加一个弹出窗口。该窗口将显示可用类别的列表。弹出窗口的相关代码如下所示:

onCreate
: 弹出窗口:
public-PopupWindow-ppoppupwindowdogs()
{
最终PopupWindow localPopupWindow=新PopupWindow(此);
ListView lv=新的ListView(本);
lv.setAdapter(新的MyCustomArrayAdapter_POP(DB_Ex_ListActivity.this));
lv.setOnItemClickListener(新的OnItemClickListener()
{
public void onItemClick(AdapterView父对象、视图、整型位置、长id)
{
如果(位置==0)
{
} 
localPopupWindow.Disclose();
}
});
localPopupWindow.setFocusable(true);
localPopupWindow.setOutsideTouchable(真);
setBackgroundDrawable(新的ColorDrawable(android.graphics.Color.TRANSPARENT));
localPopupWindow.setWidth(Constants.SCREEN_W/2);
localPopupWindow.setHeight(Constants.SCREEN_H);
localPopupWindow.setContentView(lv);
返回localPopupWindow;
}
私有类MyCustomArrayAdapter_POP扩展BaseAdapter
{
私人停车场;
私有上下文mContext=null;
公共MyCustomArrayAdapter_POP(上下文)
{  
mContext=上下文;
mInflater=LayoutInflater.from(mContext);
}  
public int getCount()
{
返回localArrayList.size();
}
公共对象getItem(int arg0)
{
返回localArrayList.get(arg0);
}
公共长getItemId(int位置)
{
返回位置;
}
公共视图getView(int位置、视图转换视图、视图组父视图)
{
if(convertView==null)
{
convertView=mInflater.充气(R.layout.listview_项,空);
}
TextView lv_item_text=(TextView)convertView.findViewById(R.id.lv_item_text);
lv_item_text.setText(category_list.get(position));
}
convertView.setLayoutParams(新的ListView.LayoutParams((int)(常数.SCREEN_W/2),(int)(常数.SCREEN_W/7));
返回视图;
}
}
问题: 按下按钮时,弹出窗口不显示。 Logcat报道


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

在调用ShowAs下拉列表下方添加以下代码行

   popupWindowDogs.update(v,200,300 );
根据弹出窗口的宽度和高度调整200和300

就这样

lv.setOnItemClickListener(新的OnItemClickListener(){
lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                  if (position == 0) 
                    {

                    } else{

                          localPopupWindow.dismiss();
                       }
              }
        });
public void onItemClick(AdapterView父对象、视图、整型位置、长id){ 如果(位置==0) { }否则{ localPopupWindow.Disclose(); } } });

将您的localPopupWindow.Disclease()调用放在else中,因为当if条件失败时,它将执行下一行,即localPopWindow。dimiss()

也有同样的问题。[这个答案][1]对我有用。[1]:
public PopupWindow ppopupWindowDogs() 
    {
        final PopupWindow localPopupWindow = new PopupWindow(this);
        ListView lv = new ListView(this);                                               
        lv.setAdapter(new MyCustomArrayAdapter_POP(DB_Ex_ListActivity.this));
        lv.setOnItemClickListener(new OnItemClickListener() 
        {
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
              {
                  if (position == 0) 
                    {

                    } 

                    localPopupWindow.dismiss();
              }
        });

        localPopupWindow.setFocusable(true);
        localPopupWindow.setOutsideTouchable(true);
        localPopupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        localPopupWindow.setWidth(Constants.SCREEN_W / 2);
        localPopupWindow.setHeight(Constants.SCREEN_H );
        localPopupWindow.setContentView(lv);
        return localPopupWindow;
    }

    private class MyCustomArrayAdapter_POP extends BaseAdapter 
    {
        private LayoutInflater mInflater;  
        private Context mContext = null;  
        public MyCustomArrayAdapter_POP(Context context) 
        {  
            mContext = context;  
            mInflater = LayoutInflater.from(mContext);  
        }  

        public int getCount() 
        {
            return localArrayList.size();
        }

        public Object getItem(int arg0) 
        {
            return localArrayList.get(arg0);
        }

        public long getItemId(int position) 
        {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) 
        {
            if (convertView == null) 
            {
                convertView = mInflater.inflate(R.layout.listview_item, null);
            }
            TextView lv_item_text = (TextView) convertView.findViewById(R.id.lv_item_text);
            lv_item_text.setText(category_list.get(position));
            }
            convertView.setLayoutParams(new ListView.LayoutParams((int)(Constants.SCREEN_W/2), (int)(Constants.SCREEN_W/7)));
            return convertView;
        }
    }
   popupWindowDogs.update(v,200,300 );
lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                  if (position == 0) 
                    {

                    } else{

                          localPopupWindow.dismiss();
                       }
              }
        });