我需要为Textview设置文本

时间:2015-11-04 05:56:14

标签: android

如何为在线性布局中动态生成的特定ID设置文本视图文本

else if(j==4)
              {
                 tvprodpcs_tot = new TextView(this);
                  tvprodpcs_tot.setInputType(InputType.TYPE_CLASS_NUMBER); 
                  tvprodpcs_tot.setId(+i );     
                  int totid=tvprodpcs_tot.getId();
                  tvprodpcs_tot.setBackgroundResource(R.drawable.edittext);
                  tvprodpcs_tot.setHeight(60);                    
                  tvprodpcs_tot.setPadding(0, 15,0, 15);
                  tvprodpcs_tot.setTextColor(Color.parseColor("#0000E6"));
                  tvprodpcs_tot.setBackgroundColor(Color.parseColor("#A2FF74"));        
                // tvprodpcs_tot.setVisibility(View.INVISIBLE); 
                // tvprodpcs_tot.setText("a");
                  tvprodpcs_tot.setLayoutParams(new LinearLayout.LayoutParams(0,90, 20));
                  tvprodpcs_tot.setGravity(Gravity.RIGHT);
                linearLayout.addView(tvprodpcs_tot); 
             }

**我需要在子布局**中设置文本

LinearLayout pLayout= (LinearLayout) findViewById(R.id.LinLayStkSub); 
         if (pLayout == null)
         {
             return;
         }       
          TotClo=0; TotCloKg=0;TotPcs=0;
          int rows=pLayout.getChildCount();      
          for(int i = id; i < pcount ; i++) 
         { 
            if ((pLayout.getChildAt(i) instanceof LinearLayout) )
            {
                LinearLayout  SubLayout = (LinearLayout) pLayout.getChildAt(i);

                for(int j = 0; j < SubLayout.getChildCount(); j++) 
                {   }

1 个答案:

答案 0 :(得分:0)

试试这个,

TextView txtResMemberAge = new TextView(RegistrationPatientActivity.this);
txtResMemberAge.setLayoutParams(lparams);
txtResMemberAge.setText("Member Age: " +familyMemberModel.getStrMemberAge());
                    txtResMemberAge.setTypeface(Typeface.createFromAsset(getAssets(), "Roboto-Regular.ttf"));
txtResMemberAge.setTextSize(14);
txtResMemberAge.setTextColor(Color.parseColor("#9C9C9C"));
linearLayout.addView(txtResMemberAge);
lparams.setMargins(50, 10, 0, 0);