notifyDataSetChanged() не будет вызывать getView() в адаптере GridView

Я создаю приложение, которое использует GrirdView, полный кнопок. Я понимаю, что после изменения цвета кнопки адаптер gridView не будет обновлять его немедленно. Я попытался добавить функцию "обновить" в адаптер и работать с ней, но это не сработало. Это мои getView() и refresh() в моем адаптере:

public View getView(final int position, View convertView, ViewGroup viewGroup) {
    View row = convertView;
    ViewHolder holder;
    //checks if the gridview is new- to inflate only once.
    if (row == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.single_item, viewGroup, false);
        holder = new ViewHolder(row);
        row.setTag(holder);
    }
    //else- using the old holder.
    else {
        //using the Tag to save the findViewById
        holder = (ViewHolder) row.getTag();
    }
    holder.btnSqure = changeBtnSize(holder.btnSqure);
    if(position!=0||postion0flag==false) {
        final Button btn = holder.btnSqure;//final to call in inner class.
        Point p = intPositionToPoint(position);
        gm.gameScreen.board.addButtonToCell(btn, p.x, p.y);
        holder.btnSqure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gm.getUserClicks) {
                    Point p = intPositionToPoint(position);
                    gm.game(p, btn);
                    // gm.game(p, gm.cells[p.x][p.y].getButton());
                }
            }
        });
    }
    if(position==0)
        postion0flag=true;
    return row;
}

обновить ():

public void refresh(Cell[][] cells,Point position)
{
    this.cells[position.x][position.y]=cells[position.x][position.y];
    notifyDataSetChanged();
}

Это часть моих "игровых" функций (здесь я называю drawTheMove, а затем пытаюсь добавить перерыв в игре, используя нить):

if (isValid(p)) {
    addChoice(p);
    drawTheMove(btn, p);
    if (!onePlayer) {
        gameScreen.changeImageTurn(numOfClick);
        turn++;//if there is only one player, keep the turn at "his side"
    }
    if (compLevel != 0) { //vs computer
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

это функция drawTheMove, которая вызывает обновление:

public void drawTheMove(Button btn,Point p) {
    btn.setText(Integer.toString(getNumOfClick()));
    Player player = getLastPlayerPlay();
    btn.setBackgroundResource(player.getImageId());
    cells[p.x][p.y].setButton(btn);
    gameScreen.board.gridViewAdapter.refresh(cells,p);
    gameScreen.board.boardGrid.invalidateViews();
}

0 ответов

Другие вопросы по тегам