Android有什么方法可以获取当前网页浏览中的gridview数据?

时间:2016-07-25 10:39:55

标签: android android-gridview baseadapter android-pageradapter

我有一个具有多视图级别的日历应用程序:DayView,MonthView,YearView。

在课堂上,CalendarPagerAdapter扩展了PagerAdapter:

    Context mContext;
    Calendar initDate; // init date is displayed on page 100, by default init date is current date
    int viewLevel;  // 0: century view, 1 decade view, 2: year view, 3: month view, 4: day view
    int totalPage;
    CalendarBaseAdapter gridAdapter;

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = generateView(position);
        container.addView(view);
        return view;
    }
public View generateView(int position){
    Calendar viewData = getData(position);
    if(viewLevel != 4) {
        GridView gridView = new GridView(mContext);
        gridView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        /** Some code here */

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                initDate = gridAdapter.getData(position);
                if(mContext instanceof LunarCalendar){
                    ((LunarCalendar)mContext).changeViewLevel(1);
                }
                Toast.makeText(mContext, "Init date " + initDate.getTime().toString(), Toast.LENGTH_LONG).show();
                Log.i("INFO", "Init Date " + initDate.getTime().toString());
            }
        });
        Log.i("INFO", "GridView was generated for " + viewData.getTime().toString());
        return gridView;
    } else{ // lunar day view
        LayoutInflater inflater = LayoutInflater.from(mContext);
        ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.lunar_day_view, null, false);

        /** Some code here */

        return layout;
    }

问题是:当我访问2016/07/25的yearView时,将显示今年的12个月并记录如下:

07-25 16:11:35.016 I/INFO: GridView was generated for Mon Jul 25 16:11:01 GMT+07:00 2016
07-25 16:11:35.018 I/INFO: GridView was generated for Sat Jul 25 16:11:01 GMT+07:00 2015
07-25 16:11:35.020 I/INFO: GridView was generated for Tue Jul 25 16:11:01 GMT+07:00 2017

当我点击月份&#34; Jul&#34;我的gridview显示数据为&#34; 2017/07/25&#34;但我的预期数据是&#34; 2016/07/25&#34;(见下面的日志)

07-25 17:27:46.096 I/INFO: Init Date Tue Jul 25 16:11:01 GMT+07:00 2017
07-25 17:27:46.099 I/INFO: GridView was generated for Tue Jul 25 16:11:01 GMT+07:00 2017
07-25 17:27:46.102 I/INFO: GridView was generated for Sun Jun 25 16:11:01 GMT+07:00 2017
07-25 17:27:46.106 I/INFO: GridView was generated for Fri Aug 25 16:11:01 GMT+07:00 2017

如何获取当前的gridView数据?

0 个答案:

没有答案