Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to add textview in a layout programmatically the textview is added on layout but it's not visible.

I have created a method setSelectedContactTextView() which is called from onResume() the method adds textview but not make them visible on screen.

Here is my code:

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++;
                }
            }
        });
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
216 views
Welcome To Ask or Share your Answers For Others

1 Answer

You may try refering to this code

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

also make sure that the layout params you're creating are LinearLayout.LayoutParams...

Or try this code

 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);
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...