今天的日期是 05/01/2017 但它显示在 29/01/2017.Which 使用 gridview 的方法对我来说很好

Todays date is 05/01/2017 but it is showing on 29/01/2017.Which method is good for me using gridview

[1]这是我的适配器页面

 if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.programlist, null);
            //holder.tv=(TextView) convertView.findViewById(R.id.txtdate);

        }
        Calendar cal = Calendar.getInstance();
        int month = cal.get(Calendar.MONTH);
        int year = cal.get(Calendar.YEAR);
        int dayofmonth = cal.get(Calendar.DAY_OF_MONTH);

        ImageView imgTv = (ImageView) convertView.findViewById(R.id.imageView1);
        Toast.makeText(context, ""+month, Toast.LENGTH_SHORT).show();

        imgTv.setImageResource(imageId[position]);
         if(currentFragmentMonth != -1 && month==currentFragmentMonth && year==2017) {

             if (dayofmonth == position+1 ) {
          imgTv.setBackgroundColor(Color.BLUE);
                 Toast.makeText(context, "You selected at position " + position, Toast.LENGTH_LONG).show();

        }


        }



        return convertView;
    }

    public void setCurrentFragmentMonth(int month)
    {
        this.currentFragmentMonth = month;
    }

}

这是我的月份代码

    Context context;
    ArrayList prgmName;
    GridView gv;
    TextView textView_date;
        int month,day,year;
    int currentFragmentMonth = -1;


    public static int [] prgmImages={R.drawable.one,R.drawable.eight,R.drawable.fifteen,R.drawable.twentytwo,R.drawable.twentynine,R.drawable.two ,R.drawable.nine,R.drawable.sixteen,R.drawable.twentythree,R.drawable.thirty,R.drawable.three,R.drawable.ten,R.drawable.seventin,R.drawable.twentyfour,R.drawable.thirtyone,R.drawable.four,R.drawable.eleven,R.drawable.eighteen,R.drawable.twentyfive,R.drawable.blank,R.drawable.five,R.drawable.twelve,R.drawable.nineteen,R.drawable.twentysix,R.drawable.blank,R.drawable.six,R.drawable.thirteen,R.drawable.twenty,R.drawable.twentyseven,R.drawable.blank,R.drawable.seven,R.drawable.fourteen,R.drawable.twentyone,R.drawable.twentyeight,R.drawable.blank};



    public January_Fragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_january_, null);
        gv = (GridView) view.findViewById(R.id.gridView1);
//        textView_date= (TextView) view.findViewById(R.id.txtdate);
//        String TextView_Date=textView_date.getText().toString();
//        int Text_Date= Integer.parseInt(TextView_Date);
        CustomAdapter customAdapter=new CustomAdapter(getActivity(),prgmImages);
        customAdapter.setCurrentFragmentMonth(0);
        // gv.setAdapter(new CustomAdapter(getActivity(), prgmImages));
        gv.setAdapter(customAdapter);

设计[我想显示背景颜色蓝色(边框颜色)特定日期明智但我的边框颜色不显示当前位置和当前 date.Todays 日期是 05/01/2017 但它显示在 29 /01/2017.Which方法适合me.Thank你][2]

enter image description here

我认为问题在于您已根据日历对数组进行排序,以便它可以垂直显示日期,但同时突出显示您考虑的位置的当前日期。

例如当前日期为 5,位于第 5 号位置。图像数组中的 20 和位置 5 的图像为 29,这就是它被突出显示的原因。

一个解决方案可能是,您需要将图像的各个位置保存在可以使用 hashmap 的地方。因此,哈希图中的键将是月份的日期,而值将是数组中图像的位置。

所以你的 hashmap 看起来像

    +------------+------------------------+
    |    Date    | Position in img array  |
    +------------+------------------------+
    | 1          | 0                      |
    | 2          | 5                      |
    | 3          | 9                      |
    +------------+------------------------+

现在获取今天的日期并将其与哈希映射键进行比较,并获取要突出显示的位置的值。

检查下面的代码,根据你的图像数组创建哈希图。

public static int[] prgmImages = {R.drawable.one, R.drawable.eight, R.drawable.fifteen, R.drawable.twentytwo, R.drawable.twentynine,
                R.drawable.two, R.drawable.nine, R.drawable.sixteen, R.drawable.twentythree, R.drawable.thirty,
                R.drawable.three, R.drawable.ten, R.drawable.seventin, R.drawable.twentyfour, R.drawable.thirtyone,
                R.drawable.four, R.drawable.eleven, R.drawable.eighteen, R.drawable.twentyfive, R.drawable.blank,
                R.drawable.five, R.drawable.twelve, R.drawable.nineteen, R.drawable.twentysix, R.drawable.blank,
                R.drawable.six, R.drawable.thirteen, R.drawable.twenty, R.drawable.twentyseven, R.drawable.blank,
                R.drawable.seven, R.drawable.fourteen, R.drawable.twentyone, R.drawable.twentyeight, R.drawable.blank};

    HashMap<Integer, Integer> map = new HashMap<>();//Hashmap<DatesInMonth,ImagePositionInArray>
    map.put(1, 0);
    map.put(2, 5);
    map.put(3, 10);
    map.put(4, 15);
    map.put(5, 20);
    map.put(6, 25);
    map.put(7, 30);
    map.put(8, 1);
    map.put(9, 6);
    map.put(10, 11);
    map.put(11, 16);
    map.put(12, 21);
    map.put(13, 26);
    map.put(14, 31);
    map.put(15, 2);
    map.put(16, 7);
    map.put(17, 12);
    map.put(18, 17);
    map.put(19, 22);
    map.put(20, 27);
    map.put(21, 32);
    map.put(22, 3);
    map.put(23, 8);
    map.put(24, 13);
    map.put(25, 18);
    map.put(26, 23);
    map.put(27, 28);
    map.put(28, 33);
    map.put(29, 4);
    map.put(30, 9);
    map.put(31, 14);

    imgTv.setImageResource(imageId[position]);
    if (currentFragmentMonth != -1 && month == currentFragmentMonth && year == 2017) {

        int mapPosition = map.get(dayofmonth);

        if (mapPosition == position) {
            imgTv.setBackgroundColor(Color.BLUE);
        }

    }