Android 为什么动态生成的内容不会显示在tablelayout中

Android 为什么动态生成的内容不会显示在tablelayout中,android,dynamic,android-tabhost,fragment,android-tablelayout,Android,Dynamic,Android Tabhost,Fragment,Android Tablelayout,我试图将一些按钮加载到片段内的表布局中。为什么这不会出现。我看到更改背景是可行的(在onCreateView(……)中从灰色更改为红色),但当我调用loadAllButtons时,它们不会显示出来 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if(container == null) return nu

我试图将一些按钮加载到片段内的表布局中。为什么这不会出现。我看到更改背景是可行的(在onCreateView(……)中从灰色更改为红色),但当我调用loadAllButtons时,它们不会显示出来

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
        if(container == null)
            return null;
        basedView = (TableLayout) inflater.inflate(R.layout.fragment_difficult_sound_syllable, container, false);
        currentSyllable = getArguments().getString(StaticValues.DIFFICULT_SOUND_SELECTOR);

        basedView.setBackgroundColor(Color.RED);
        return basedView;
}
下面是我的loadAllButtons,在任何人询问是之前,它表示所有内容都已加载(例如添加的按钮和行,在row.add()和basedView.add()之后通过logcat进行检查)

private void loadAllButtons()
{
DataBaseHelper tmpHelper=新的DataBaseHelper(getActivity().getApplicationContext());
ArrayList tmpArray=null;
if(currentSymplete.contentEquals(StaticValues.CONSONANT))
{
tmpArray=tmpHelper.returnallconsonates();
Log.i(StaticValues.TAG,“返回所有辅音”);
}
其他的
{
tmpArray=tmpHelper.returnAll元音();
Log.i(StaticValues.TAG,“返回所有元音”);
}
如果(tmpArray!=null)
{
TableRow行=null;
InfoButton tmpButton=null;
//LayoutParams rowParams=新的LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
//TableRow.LayoutParams equalParams=新的TableRow.LayoutParams(LayoutParams.WRAP_内容,LayoutParams.WRAP_内容,0);
LinearLayout.LayoutParams buttonLayout=新建LinearLayout.LayoutParams(LayoutParams.FILL\u父级,LayoutParams.FILL\u父级);
if(basedView!=null)
{
对于(int i=0;i

出于某种原因,即使我的logcat输出显示一切都很好(显示专有名称的按钮和正确数量的按钮),它们的表格布局也没有填充。

找到了关于我自己问题的答案。之后的一切

tmpButton = (InfoButton) getLayoutInflter()...

必须删除,除非

tmpButton.setText();


虽然我不知道为什么那些杀了我的布局。因此,如果有人知道了这一部分,我很乐意接受这个答案。

似乎你的问题是布局参数。是的,可能。这是以前活动中的复制粘贴代码。它在那里起作用,但在碎片中不起作用。很奇怪。
row.addView(tmpButton);
tmpButton.setText();
tmpButton.setExtraInfo(..);