Java 通过编程方式添加的Android表行是不可见的

Java 通过编程方式添加的Android表行是不可见的,java,android,Java,Android,下面是动态添加TableRows的代码片段 TableLayout tl=(TableLayout)findviewbyd(R.id.MyTable) 有人能告诉我为什么在运行这个程序时,我在android应用程序上没有看到任何文本视图。 没有引发异常,但输出仍然为空。 我在这里遗漏了什么吗?在添加新行后尝试调用invalidate()。这就是我所说的快速解决方案。。。你太棒了。。。工作得很有魅力!!!很抱歉我被结果迷住了,但我已经解决了问题。这不是由于无效,但在上面的代码tv.SetLayou

下面是动态添加TableRows的代码片段

TableLayout tl=(TableLayout)findviewbyd(R.id.MyTable)

有人能告诉我为什么在运行这个程序时,我在android应用程序上没有看到任何文本视图。 没有引发异常,但输出仍然为空。
我在这里遗漏了什么吗?

在添加新行后尝试调用invalidate()。

这就是我所说的快速解决方案。。。你太棒了。。。工作得很有魅力!!!很抱歉我被结果迷住了,但我已经解决了问题。这不是由于无效,但在上面的代码tv.SetLayoutParams中是导致问题的原因。我一把它取下来,它就开始为我工作,而且没有失效。我不知道这是如何解决问题的,但对我来说是有效的。有人能回答这个问题是如何解决的吗?否则我将不得不用谷歌搜索……)你能试试这个吗。。。LinearLayout.LayoutParams params=新的LinearLayout.LayoutParams(LayoutParams.MATCH_父项,LayoutParams.WRAP_内容,1f);tv.setLayoutParams(参数);
    try
    {
        AssetManager assetManager = getAssets();
        InputStream ims = assetManager.open("TempData.xml");
        InputStreamReader reader = new InputStreamReader(ims);
        XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
         parser.setInput(reader);
         parser.require(XmlPullParser.START_DOCUMENT, null, null);

         int eventType = parser.getEventType();

         int count = 0;
         while(eventType != XmlPullParser.END_DOCUMENT) {
            String pName = parser.getName();
            switch(eventType) {
               case XmlPullParser.START_TAG:
                  if(pName.equals("name")) {

              String msg = parser.nextText();
                     //Update the Table with this data
                     TableRow tr = new TableRow(this);
                     tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
                     TextView tv = new TextView(this);
                    tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

                     tv.setText(msg);
                     tv.setVisibility(View.VISIBLE);
                    tr.addView(tv);
                     tr.setVisibility(View.VISIBLE);
                     tl.addView(tr);

                //This below code is just to confirm that i am readin the correct data from XML. It is correct btw.
                    Context context = getApplicationContext();
                    CharSequence text = "data is : " + msg;
                    int duration = Toast.LENGTH_SHORT;
                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                    //Thread.sleep(2);
                  break;
                  }

               default:
                  break;
            } 

            eventType = parser.next();
         }// parse next and gen
    }
    catch(Exception e){
        String ExceptionMessage = e.getLocalizedMessage();
        Context context = getApplicationContext();
        CharSequence text = "Error is : " + ExceptionMessage;
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }