0

我正在尝试以textview编程textview方式添加布局,但它不可见。

我创建了一个方法,该方法从添加的方法setSelectedContactTextView()中调用,但没有使它们在屏幕上可见。onResume()textview

这是我的代码:

protected void onResume() {

        if(Constants.fbContactListArrayList!=null && Constants.fbContactListArrayList.size()!=0){
            setSelectedContactTextView(Constants.fbContactListArrayList);
        }
        super.onResume();
    }

    //SET SELECTED CONTACTS IN TEXTVIEW FORMS
    public void setSelectedContactTextView(final ArrayList<Object> list){
        //Constants.progressDialog=ProgressDialog.show(this, "", Constants.MSG_PROGESSDIALOG);
        new Thread(new Runnable() {

            @Override
            public void run() {
                while(i<list.size()){
                    ContactBean contactBean=(ContactBean)list.get(i);
                    if(contactBean.isSelected()==true){
                        TextView contactTextView=new TextView(NewEventShowDetails.this);
                        contactTextView.setText(contactBean.getUserName().toString());
                        fbContactTextLinearLayout.addView(contactTextView);
                    }
                    i++;
                }
            }
        });
    }
4

1 回答 1

2

您可以尝试参考此代码

LinearLayout linearLayout = (LinearLayout)findViewById(R.id.info)
...
linearLayout.addView(valueTV);

还要确保layout您创建的参数是LinearLayout.LayoutParams...

或者试试这个代码

 LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
 String[] informations = new String[] { "one", "two", "three" };
 TextView informationView;

  for (int i = 0; i < informations.length; i++) {
    View line = new View(this);
    line.setLayoutParams(new LayoutParams(1, LayoutParams.MATCH_PARENT));
    line.setBackgroundColor(0xAA345556);
    informationView = new TextView(this);
    informationView.setText(informations[i]);
    layout.addView(informationView, 0);
    layout.addView(line, 1);
 }
于 2013-05-24T08:29:23.170 回答