Android:TextView没有显示

时间:2014-06-03 08:01:58

标签: android textview tablerow

我正在尝试动态添加TableRow取决于我从服务器获得的请求但是当我运行应用程序时没有发生任何事情,否则表头从右侧推送。

@SuppressLint("NewApi")
protected void getClientTransaction(JSONArray transactionsArrayInfo)
{
    int transactionsArraySize = transactionsArrayInfo.length();

    for(int i = 0 ; i < transactionsArraySize ; i++ )
    {

        final String senderID = transactionDetails.getString("src_mymoid");
        runOnUiThread(new Runnable() {
            public void run() 
            {
                try
                {
                    TableRow row = new TableRow(Transactions.this);
                    row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

                    TextView senderIDTextView = new TextView(Transactions.this);
                    senderIDTextView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                    senderIDTextView.setId(100);
                    senderIDTextView.setPadding(10, 10, 10, 10);
                    senderIDTextView.setTextColor(Color.BLACK);
                    senderIDTextView.setBackgroundColor(Color.RED);
                    senderIDTextView.setText(senderID);

                    row.addView(senderIDTextView);
                    transactions_table.addView(row , new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));                                           
                }
                catch(Exception ex)
                {
                    Toast.makeText(getBaseContext(), ex.toString(), Toast.LENGTH_LONG).show();
                }

            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您使用了原生布局参数作为操作栏,而不是使用它来使用tablerow的layoutparams。

<强>解决方案

将导入更改为

android.widget.TableRow.LayoutParams