如何在自定义适配器类中创建PopUp窗口?

时间:2012-09-06 09:13:55

标签: android android-arrayadapter popupwindow

我搜索了很多网站来创建popUp窗口,但我没有在Custom Adapter类中创建弹出窗口的正确解决方案,我发现只能在Activity类中创建popUp窗口。

我的问题是我正在使用Custom Adapter类扩展ArrayAdapter,因为我在row.xml文件中有一个适用于ArrayList的TextView。当我点击那个textview时,我想在光标点位置显示popUp窗口。

这是我的代码:

Clockin_Adapter adap = new Clockin_Adapter(getApplicationContext(), R.layout.group_clkin_row, result);
            clockin.setAdapter(adap);

public static class Clockin_Adapter extends ArrayAdapter<DataItem> {

        ArrayList<DataItem> items;
        Context con;
        int[] buttonStates;
        Time t ;

        public Clockin_Adapter(Context context, int textViewResourceId, ArrayList<DataItem> objects) {
            super(context, textViewResourceId, objects);
            this.con = context;
            this.items = objects;

            buttonStates=new int[objects.size()];
            for(int i=0;i<objects.size();i++)
            {
            buttonStates[i]=0;
            }
        }
        @Override
        public int getCount() {         

             if(employeeList==null){
                    return 0;
                }
                else{
                    return employeeList.length;
                }

        }

        @Override
        public long getItemId(int position) {           
            return 0;
        }
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            View row = convertView;
            final ViewHolder holder;
            if (convertView == null) {
            row = LayoutInflater.from(parent.getContext()).inflate(R.layout.group_clkin_row, null);
            holder=new ViewHolder();
            } else {
                //code

                }

            }

                holder.name = (TextView)row.findViewById(R.id.group_name);

                holder.name.setText(item.getName());
                holder.name.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {


                        //Need PopUp window Here

                    }
                });

static class ViewHolder {
        TextView name;
        TextView time;

        }


please give me solution.


Thanks in advanced.

1 个答案:

答案 0 :(得分:0)

自定义浮动窗口:

您可以将dialog.setContentView(R.layout.custom);更改为dialog.setView(//your view);

final Dialog dialog = new Dialog(con);
            dialog.setContentView(R.layout.custom);
            dialog.setTitle("Title...");