滑块菜单查看问题

时间:2014-02-25 16:03:23

标签: android view slider viewgroup android-sliding

我在一个单独的项目中实现了一个ListView来自sqlite的头文件,如下所示:

enter image description here

当我在滑块菜单的位置实现onClick()时,它显示在滑块菜单中而不是后台View

enter image description here

onCreate()代码段

if(position == 3)
{
    mAdapter = new MyCustomAdapter();
    mAdapter.addSeparatorItem(q.get(0).getA_name());
    mAdapter.addItem(q.get(0).getAS_name());
    for (int i = 1; i < 460; i++) { 
        if (!(q.get(i).getA_name().trim().equals(q.get(i-1).getA_name().trim()))) {
            mAdapter.addSeparatorItem(q.get(i).getA_name());
            c++;
        }
        mAdapter.addItem(q.get(i).getAS_name());
    }
    setListAdapter(mAdapter);
    toggleMenu(arg1);  
}

适配器类

 //Adapter Class
 private class MyCustomAdapter extends BaseAdapter {

        private static final int TYPE_ITEM = 0;
        private static final int TYPE_SEPARATOR = 1;
        private static final int TYPE_MAX_COUNT = TYPE_SEPARATOR + 1;

        private ArrayList<String> mData = new ArrayList<String>();
        private LayoutInflater mInflater;

        private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();

        public MyCustomAdapter() {
            mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        public void addItem(final String item) {
            mData.add(item);
            notifyDataSetChanged();
        }

        public void addSeparatorItem(final String item) {
            mData.add(item);
            // save separator position
            mSeparatorsSet.add(mData.size() - 1);
            notifyDataSetChanged();
        }

        @Override
        public int getItemViewType(int position) {
            return mSeparatorsSet.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
        }

        @Override
        public int getViewTypeCount() {
            return TYPE_MAX_COUNT;
        }

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

        public String getItem(int position) {
            return mData.get(position);
        }

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

        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            int type = getItemViewType(position);
            System.out.println("getView " + position + " " + convertView + " type = " + type);
            if (convertView == null) {
                holder = new ViewHolder();
                switch (type) {
                    case TYPE_ITEM:
                        convertView = mInflater.inflate(R.layout.activity_main1, null);
                        holder.textView = (TextView)convertView.findViewById(R.id.text);
                        holder.textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                AlertDialog.Builder nointernetconnection = new AlertDialog.Builder(
                                        temp);
                                nointernetconnection
                                        .setIcon(R.drawable.ic_launcher)
                                        .setTitle(q.get(position-1).getAS_name())
                                        .setMessage(q.get(position-1).getDesc_art())
                                        .setCancelable(true)
                                        .setPositiveButton("OK",
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface arg,
                                                            int arg1) {

                                                    }
                                                });
                                AlertDialog a = nointernetconnection.create();
                                a.show();
                            }
                      });
                        break;
                    case TYPE_SEPARATOR:
                        convertView = mInflater.inflate(R.layout.activity_main2, null);
                        holder.textView = (TextView)convertView.findViewById(R.id.textSeparator);
                        break;
                }
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder)convertView.getTag();
            }
            holder.textView.setText(mData.get(position));
            return convertView;
        }

    }

    public static class ViewHolder {
        public TextView textView;
    }

因此,MyCustomAdapter类在滑块菜单中显示该列表。但是此列表不应显示在滑块菜单中,而应显示在滑块菜单后面。我希望问题很清楚。请告诉我的错误。

1 个答案:

答案 0 :(得分:0)

正在为滑块调用您正在调用的setlistadapter方法,而不是后台活动/片段的列表视图。 执行ListView list = (ListView) getactivity().findViewById(R.id.yourListViewName)或类似的操作,然后设置列表适配器。