数组列表大小在if条件之外返回零大小?

时间:2017-05-16 06:31:15

标签: android arraylist

我有一个存储在其中的三个元素的数组列表。在if条件中我删除了一个元素,它删除了罚款,但当我检查数组列表的大小在if条件之外它返回零值。请任何人帮助me.i已经按照这些步骤......

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv_moves = (TextView) findViewById(R.id.tv_moves);
    tv_time = (TextView) findViewById(R.id.tv_time);
    ArrayList<Integer> arl = new ArrayList<Integer>();
    arl.add(1);
    arl.add(2);
    arl.add(3);
    ArrayList<Integer>remain=new ArrayList<>();
    mGrid = (GridLayout) findViewById(R.id.grid_layout);
    inflater = LayoutInflater.from(this);
    for (int i = 0; i < NBR_ITEMS; i++) {
        final View itemView = inflater.inflate(R.layout.item_grid, mGrid, false);
        final TextView text = (TextView) itemView.findViewById(R.id.text);
        if (i == 4) {
            itemView.setEnabled(false);
            itemView.setBackgroundColor(Color.parseColor("#999999"));
            int index = randomGenerator.nextInt(arl.size());
            Integer item1 = arl.get(index);
            text.setText(item1.toString());
            array[4] = item1.toString();
            arl.remove(index);
            System.out.println("array element list==="+arl);
            remain.add(0,arl.get(0));
            remain.add(1,arl.get(1));
            checkSubmit();
            text.setPadding(60, 30, 10, 10);

        }
        if (i == 3) {
            System.out.println("size of array list at 3=="+arl.size());//here i got the size 3 but i think it should be 2


           itemView.setEnabled(false);
            itemView.setBackgroundColor(Color.parseColor("#999999"));
            int index = randomGenerator.nextInt(arl.size());
            Integer item2 = arl.get(index);
            text.setText(item2.toString());

            array[3] = item2.toString();
            checkSubmit();
            text.setPadding(60, 30, 10, 10);
        }

0 个答案:

没有答案