未选择的gridview项目?

时间:2016-11-30 00:12:55

标签: android gridview

我有一个有问题的游戏项目。我的游戏中有一个20项的网格。用户应选择多项==主号码(6 + 2 + 4 + 8 == 20)

screen of my game: Grid items

当点击位于9(两位数)以上的项目时,本身和第一项都被选中。对于考试:按位置14的项目:项目14&单击项目14时选择项目1。

这是我的java代码: 1. grid.onItemClickListener:

if(Integer.parseInt(string.charAt(position)+"")+sum_main < Integer.parseInt(tv.getText().toString())){
            // define action when: sum_main < Number
            sum_main  += Integer.parseInt(string.charAt(position)+"");
            String sm = position+"";
            if(sm.length() > 1){
                Log.d("11","Ok");
                sbVars.append(slash);
                sbVars.append(string.charAt(position));
                sbPoss.append(slash);
                sbPoss.append(position);
                Log.d("12","Ok");
            }else{ Log.d("13","Ok");
                sbVars.append(string.charAt(position));
                sbPoss.append(position); Log.d("14","Ok");
            }
            view.setEnabled(false);
            Log.d("15","Ok");
            n = 1;
            Toast.makeText(MplusN_Game.this, sbPoss+"", Toast.LENGTH_LONG).show();
        }else if(Integer.parseInt(string.charAt(position)+"")+sum_main == Integer.parseInt(tv.getText().toString())){
            // define action when: sum_main = Number
            sum_main = 0;
            String sm = position+"";
            if(sm.length() > 1){
                sbVars.append("/");
                sbVars.append(string.charAt(position));
                sbPoss.append("/");
                sbPoss.append(position);
            }else{
                sbVars.append(string.charAt(position));
                sbPoss.append(position);
            }
            tv.setText(setNumber()+"");
            n = 2;
            deleteVarsOfString();
        }else{
            // define action when: sum_main > Number
            sum_main = 0;
            n = 3;
        }
        setStatesGridItems(n);// method for change bg of selected items
        }
    });
  1. 这是setStateGridItems()方法 for(int i=0; i<sbPoss.length(); i++){ String s = sbPoss.charAt(i)+""; if(s.equals(slash)){ String ss = sbPoss.charAt(i+1)+""+sbPoss.charAt(i+2); int t1 = Integer.parseInt(ss); grid.getChildAt(t1).setBackgroundResource(R.drawable.bg_grid_items_bloo100); Log.w("1","OK"); } else{ Log.w("2","OK"); if(i > 1){ Log.w("21","OK"); String s2 = sbPoss.charAt(i-1)+""; String s3 = sbPoss.charAt(i-2)+""; if(s2.equals(slash)) if(s3.equals(slash)){ Log.w("211","OK"); continue; } else{ int t = Integer.parseInt(sbPoss.charAt(i)+""); grid.getChildAt(t).setBackgroundResource(R.drawable.bg_grid_items_bloo100); grid.getChildAt(t).setEnabled(false); Log.w("212","OK"); } }else{ Log.w("22","OK"); if(i==0){ int t = Integer.parseInt(sbPoss.charAt(0)+""); grid.getChildAt(t).setBackgroundResource(R.drawable.bg_grid_items_bloo100); grid.getChildAt(t).setEnabled(false); Log.w("221","OK"); }else{ Log.w("222","OK"); String s2 = sbPoss.charAt(i-1)+""; if(s2.equals(slash)){ Log.w("2221","OK"); continue; } else{ Log.w("2222","OK"); int t = Integer.parseInt(sbPoss.charAt(i)+""); grid.getChildAt(t).setBackgroundResource(R.drawable.bg_grid_items_bloo100); grid.getChildAt(t).setEnabled(false); } } } } }
  2. 请解决此问题。谢谢

0 个答案:

没有答案