Java TableLayout中未显示TableRow

Java TableLayout中未显示TableRow,java,android,android-layout,Java,Android,Android Layout,有人能看出下面的错误吗: if (mViewPager.getCurrentItem() == 3){ TableLayout tbl = (TableLayout)findViewById(R.id.tblHistory); if (tbl.getChildCount() != mExceptions.size()){ for (int i = tbl.g

有人能看出下面的错误吗:

                if (mViewPager.getCurrentItem() == 3){
                TableLayout tbl = (TableLayout)findViewById(R.id.tblHistory);

                if (tbl.getChildCount() != mExceptions.size()){

                    for (int i = tbl.getChildCount(); i < mExceptions.size(); i++){
                        GPSException e = mExceptions.get(i);

                        //TableRow
                        TableRow tr = new TableRow(this);
                        tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                        tr.setBackgroundColor(Color.BLACK);

                        //DateTime
                        TextView tx = new TextView(this);
                        tx.setLayoutParams(new android.view.ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                        tx.setText(e.DateTime);
                        tx.setTextAppearance(getApplicationContext(), android.R.attr.textAppearanceMedium);
                        tx.setTextColor(Color.BLACK);
                        tx.setBackgroundColor(Color.WHITE);
                        tr.addView(tx);

                        //Speed
                        tx = new TextView(this);
                        tx.setLayoutParams(new android.view.ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                        tx.setText(Float.toString(e.Speed));
                        tx.setTextAppearance(getApplicationContext(), android.R.attr.textAppearanceMedium);
                        tx.setTextColor(Color.BLACK);
                        tx.setBackgroundColor(Color.WHITE);
                        tr.addView(tx);

                        //Bearing
                        tx = new TextView(this);
                        tx.setLayoutParams(new android.view.ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                        tx.setText(Double.toString(e.Degrees));
                        tx.setTextAppearance(getApplicationContext(), android.R.attr.textAppearanceMedium);
                        tx.setTextColor(Color.BLACK);
                        tx.setBackgroundColor(Color.WHITE);
                        tr.addView(tx);

                        //Exceptions
                        tx = new TextView(this);
                        tx.setLayoutParams(new android.view.ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                        tx.setText(e.ExceptionString());
                        tx.setTextAppearance(getApplicationContext(), android.R.attr.textAppearanceMedium);
                        tx.setTextColor(Color.BLACK);
                        tx.setBackgroundColor(Color.WHITE);
                        tr.addView(tx);

                        tbl.addView(tr, 0);
                    }

                    tbl.invalidate();
                    tbl.refreshDrawableState();
                }
            }
if(mViewPager.getCurrentItem()==3){
TableLayout tbl=(TableLayout)findViewById(R.id.tblHistory);
if(tbl.getChildCount()!=meExceptions.size()){
对于(int i=tbl.getChildCount();i
我的类实现LocationListener,上面的代码在onLocationChanged事件中激发。目的是为每个排队的“异常”向TableLayout添加一个TableRow。每行插入到位置0

除了正确的方法外,我已经尝试了所有的方法

我的布局如下(资源暂时没有使用,但在我解决了这个问题后会使用——对于所有目光敏锐的观众来说!):



没有抛出异常,如果我在for循环中吐司一条短消息,它确实会出现

如果你需要更多信息,这不是问题

谢谢

tbl.addView(tr, 0);
我想你需要给那个布局参数,而不是0。也许试试这个

tbl.addView(tr, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));

所有这些之后,删除
android.view.ViewGroup.LayoutParams
限定符(意味着每个
TextView
的布局参数现在都是
TableRow.LayoutParams
)已经修复了解决方案。为什么?我不知道


也许TextView的布局参数必须与TableRow相关???!刮这里。无论如何,问题解决了:-(

您要导入什么LayoutParams?Table row使用TableRow.LayoutParamsTextView使用android.view.ViewGroup.LayoutParams我见过其他使用不适当类型的LayoutParams的实例,不幸的是,这里不是这样(我认为……)啊,我刚刚检查了代码,LayoutParam类本身很好,但是参数不是。TextView的LayoutParam参数是TableRow。我将更改此参数并还原。谢谢,我没有看到过载。我已经尝试过,但很遗憾,它没有起作用。我想我会在当我不断地跑进跑出办公室以引起回应的那一刻!
tbl.addView(tr, 0);
tbl.addView(tr, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));