带doInBackground的android动态TableRow不工作? ///SeatLayout.java/////////// 公共类SeatLayoutActivity扩展活动 { private TableLayout雷场;//要添加地雷的表格

带doInBackground的android动态TableRow不工作? ///SeatLayout.java/////////// 公共类SeatLayoutActivity扩展活动 { private TableLayout雷场;//要添加地雷的表格,android,tablelayout,tablerow,android-asynctask,Android,Tablelayout,Tablerow,Android Asynctask,带doInBackground的android动态TableRow不工作? ///SeatLayout.java/////////// 公共类SeatLayoutActivity扩展活动 { private TableLayout雷场;//要添加地雷的表格布局 专用区块[][];//矿区区块 private int blockDimension=24;//每个块的宽度 private int blockPadding=2;//块之间的填充 私有int numberOfRowsInMineFiel

带doInBackground的android动态TableRow不工作?
///SeatLayout.java///////////
公共类SeatLayoutActivity扩展活动
{
private TableLayout雷场;//要添加地雷的表格布局
专用区块[][];//矿区区块
private int blockDimension=24;//每个块的宽度
private int blockPadding=2;//块之间的填充
私有int numberOfRowsInMineField=9;
private int numberOfColumnsInMineField=9;
公共进程对话;
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
progressDialog=progressDialog.show(SeatLayoutActivity.this,“获取数据”、“加载…”);
新建GetDataTask(SeatLayoutActivity.this).execute();
setContentView(R.layout.seatlayout);
}
私有布尔isOnline(){
ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_服务);
NetworkInfo ni=cm.getActiveNetworkInfo();
如果(ni!=null&&ni.isConnected())
返回true;
返回false;
}
私有类GetDataTask扩展了AsyncTask{
私有上下文ctx;
公共GetDataTask(上下文){
ctx=上下文;
} 
@凌驾
受保护的整数doInBackground(Void…params){
if(isOnline()){
雷场=(表格布局)findViewById(R.id.雷场);
区块=新区块[numberOfRowsInMineField+2][numberOfColumnsInMineField+2];
//下表中的功能(行数和列数)将基于重置服务响应
对于(int row=0;row//////  SeatLayout.java ///////////

public class SeatLayoutActivity  extends Activity
{
    private TableLayout mineField; // table layout to add mines to

    private Block blocks[][]; // blocks for mine field  
    private int blockDimension = 24; // width of each block
    private int blockPadding = 2; // padding between blocks

    private int numberOfRowsInMineField = 9;
    private int numberOfColumnsInMineField = 9;

    public ProgressDialog progressDialog; 

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);


         progressDialog = ProgressDialog.show(SeatLayoutActivity.this, "Getting data", "Loading...");
         new GetDataTask(SeatLayoutActivity.this).execute();  

          setContentView(R.layout.seatlayout);
    }


     private Boolean isOnline() {
            ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo ni = cm.getActiveNetworkInfo();
            if(ni != null && ni.isConnected())
                return true;

            return false;
        }

     private class GetDataTask extends AsyncTask<Void, Void, Integer> {
         private Context ctx; 
         public GetDataTask(Context context) { 
             ctx = context; 
         } 

      @Override
      protected Integer doInBackground(Void... params) {

            if(isOnline()){



                mineField = (TableLayout)findViewById(R.id.MineField);      
                blocks = new Block[numberOfRowsInMineField + 2][numberOfColumnsInMineField + 2];


                //in feature below table(number of rows and columns) will based on RESET service response

                for (int row = 0; row < numberOfRowsInMineField + 2; row++)
                {
                    for (int column = 0; column < numberOfColumnsInMineField + 2; column++)
                    {   
                        blocks[row][column] = new Block(ctx);
                        blocks[row][column].setDefaults();                      

                    }
                }

                for (int row = 1; row < numberOfRowsInMineField + 1; row++)
                {
                    TableRow tableRow = new TableRow(ctx);  
                    tableRow.setLayoutParams(new LayoutParams((blockDimension + 2 * blockPadding) * numberOfColumnsInMineField, blockDimension + 2 * blockPadding));

                    for (int column = 1; column < numberOfColumnsInMineField + 1; column++)
                    {
                        blocks[row][column].setLayoutParams(new LayoutParams(  
                                blockDimension + 2 * blockPadding,  
                                blockDimension + 2 * blockPadding)); 
                        blocks[row][column].setPadding(blockPadding, blockPadding, blockPadding, blockPadding);
                        tableRow.addView(blocks[row][column]);
                    }
                    mineField.addView(tableRow,new TableLayout.LayoutParams(  
                            (blockDimension + 2 * blockPadding) * numberOfColumnsInMineField, blockDimension + 2 * blockPadding));  
                }


            }else{
                Toast.makeText(SeatLayoutActivity.this, "No connection..", Toast.LENGTH_LONG).show();           
            }

          return 1;
      }

      @Override
      protected void onPostExecute(Integer result) {


        progressDialog.dismiss();
          super.onPostExecute(result);
      }
  }
}

///Block.java


package com.pxr.tutorial.xmltest;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.Button;

public class Block extends Button
{
    private boolean isCovered; // is block covered yet
    private boolean isMined; // does the block has a mine underneath
    private boolean isFlagged; // is block flagged as a potential mine
    private boolean isQuestionMarked; // is block question marked
    private boolean isClickable; // can block accept click events
    private int numberOfMinesInSurrounding; // number of mines in nearby blocks

    public Block(Context context)
    {
        super(context);
    }

    public Block(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public Block(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }

    // set default properties for the block
    public void setDefaults()
    {
        isCovered = true;
        isMined = false;
        isFlagged = false;
        isQuestionMarked = false;
        isClickable = true;
        numberOfMinesInSurrounding = 0;

        this.setBackgroundResource(R.drawable.square_blue);
        setBoldFont();
    }

    // mark the block as disabled/opened
    // update the number of nearby mines
    public void setNumberOfSurroundingMines(int number)
    {
        this.setBackgroundResource(R.drawable.square_grey);

        updateNumber(number);
    }

    // set mine icon for block
    // set block as disabled/opened if false is passed
    public void setMineIcon(boolean enabled)
    {
        this.setText("M");

        if (!enabled)
        {
            this.setBackgroundResource(R.drawable.square_grey);
            this.setTextColor(Color.RED);
        }
        else
        {
            this.setTextColor(Color.BLACK);
        }
    }

    // set mine as flagged
    // set block as disabled/opened if false is passed
    public void setFlagIcon(boolean enabled)
    {
        this.setText("F");

        if (!enabled)
        {
            this.setBackgroundResource(R.drawable.square_grey);
            this.setTextColor(Color.RED);
        }
        else
        {
            this.setTextColor(Color.BLACK);
        }
    }

    // set mine as question mark
    // set block as disabled/opened if false is passed
    public void setQuestionMarkIcon(boolean enabled)
    {
        this.setText("?");

        if (!enabled)
        {
            this.setBackgroundResource(R.drawable.square_grey);
            this.setTextColor(Color.RED);
        }
        else
        {
            this.setTextColor(Color.BLACK);
        }
    }

    // set block as disabled/opened if false is passed
    // else enable/close it
    public void setBlockAsDisabled(boolean enabled)
    {
        if (!enabled)
        {
            this.setBackgroundResource(R.drawable.square_grey);
        }
        else
        {
            this.setBackgroundResource(R.drawable.square_blue);
        }
    }

    // clear all icons/text
    public void clearAllIcons()
    {
        this.setText("");
    }

    // set font as bold
    private void setBoldFont()
    {
        this.setTypeface(null, Typeface.BOLD);
    }

    // uncover this block
    public void OpenBlock()
    {
        // cannot uncover a mine which is not covered
        if (!isCovered)
            return;

        setBlockAsDisabled(false);
        isCovered = false;

        // check if it has mine
        if (hasMine())
        {
            setMineIcon(false);
        }
        // update with the nearby mine count
        else
        {
            setNumberOfSurroundingMines(numberOfMinesInSurrounding);
        }
    }

    // set text as nearby mine count
    public void updateNumber(int text)
    {
        if (text != 0)
        {
            this.setText(Integer.toString(text));

            // select different color for each number
            // we have already skipped 0 mine count
            switch (text)
            {
                case 1:
                    this.setTextColor(Color.BLUE);
                    break;
                case 2:
                    this.setTextColor(Color.rgb(0, 100, 0));
                    break;
                case 3:
                    this.setTextColor(Color.RED);
                    break;
                case 4:
                    this.setTextColor(Color.rgb(85, 26, 139));
                    break;
                case 5:
                    this.setTextColor(Color.rgb(139, 28, 98));
                    break;
                case 6:
                    this.setTextColor(Color.rgb(238, 173, 14));
                    break;
                case 7:
                    this.setTextColor(Color.rgb(47, 79, 79));
                    break;
                case 8:
                    this.setTextColor(Color.rgb(71, 71, 71));
                    break;
                case 9: 
                    this.setTextColor(Color.rgb(205, 205, 0));
                    break;
            }
        }
    }

    // set block as a mine underneath
    public void plantMine()
    {
        isMined = true;
    }

    // mine was opened
    // change the block icon and color
    public void triggerMine()
    {
        setMineIcon(true);
        this.setTextColor(Color.RED);
    }

    // is block still covered
    public boolean isCovered()
    {
        return isCovered;
    }

    // does the block have any mine underneath
    public boolean hasMine()
    {
        return isMined;
    }

    // set number of nearby mines
    public void setNumberOfMinesInSurrounding(int number)
    {
        numberOfMinesInSurrounding = number;
    }

    // get number of nearby mines
    public int getNumberOfMinesInSorrounding()
    {
        return numberOfMinesInSurrounding;
    }

    // is block marked as flagged
    public boolean isFlagged()
    {
        return isFlagged;
    }

    // mark block as flagged
    public void setFlagged(boolean flagged)
    {
        isFlagged = flagged;
    }

    // is block marked as a question mark
    public boolean isQuestionMarked()
    {
        return isQuestionMarked;
    }

    // set question mark for the block
    public void setQuestionMarked(boolean questionMarked)
    {
        isQuestionMarked = questionMarked;
    }

    // can block receive click event
    public boolean isClickable()
    {
        return isClickable;
    }

    // disable block for receive click events
    public void setClickable(boolean clickable)
    {
        isClickable = clickable;
    }
}
            mineField = (TableLayout)findViewById(R.id.MineField);      
            blocks = new Block[numberOfRowsInMineField + 2][numberOfColumnsInMineField + 2];


            //in feature below table(number of rows and columns) will based on RESET service response

            for (int row = 0; row < numberOfRowsInMineField + 2; row++)
            {
                for (int column = 0; column < numberOfColumnsInMineField + 2; column++)
                {   
                    blocks[row][column] = new Block(ctx);
                    blocks[row][column].setDefaults();                      

                }
            }

            for (int row = 1; row < numberOfRowsInMineField + 1; row++)
            {
                TableRow tableRow = new TableRow(ctx);  
                tableRow.setLayoutParams(new LayoutParams((blockDimension + 2 * blockPadding) * numberOfColumnsInMineField, blockDimension + 2 * blockPadding));

                for (int column = 1; column < numberOfColumnsInMineField + 1; column++)
                {
                    blocks[row][column].setLayoutParams(new LayoutParams(  
                            blockDimension + 2 * blockPadding,  
                            blockDimension + 2 * blockPadding)); 
                    blocks[row][column].setPadding(blockPadding, blockPadding, blockPadding, blockPadding);
                    tableRow.addView(blocks[row][column]);
                }
                mineField.addView(tableRow,new TableLayout.LayoutParams(  
                        (blockDimension + 2 * blockPadding) * numberOfColumnsInMineField, blockDimension + 2 * blockPadding));  
            }


        }else{
            Toast.makeText(SeatLayoutActivity.this, "No connection..", Toast.LENGTH_LONG).show();           
        }