2014-10-18 107 views
0

我創建了包含問題文本和適合提問的輸入字段的表單。我的表單中有微調,編輯文本和複選框。 所有都是使用活動動態創建的。創建的佈局中的問題是輸入字段正確顯示,但不顯示textview。textview未顯示文本

private void showIssueForm(){ 
    for (int i=0;i<claimQuestionList.size();i++){ 
     ClaimQuestion claimQuestion=claimQuestionList.get(i); 
     LinearLayout linearLayout=ClaimUtils.createLayoutForClaimQuestion(claimQuestion,this); 
     /*claimQuestionsLinearLayout.addView(linearLayout);*/ 
     claimQuestionsLinearLayout.addView(linearLayout,i); 
    } 

} 


private static TextView createTextView(ClaimQuestion claimQuestion,Context context){            
TextView textView=new TextView(context);                      
LinearLayout.LayoutParams textViewLayoutParams=new LinearLayout.LayoutParams(300,80,1);           
textView.setText("hi m printing the text what are you looking for");//claimQuestion.getOrder()+". "+claimQuestion.getLabel()); 
textView.setLayoutParams(textViewLayoutParams);                     
//textView.setMinLines(1);                          
// textView.setSingleLine(false);                        
textView.setTextSize(R.dimen.system12);                       
textView.setVisibility(View.VISIBLE);                       
textView.setTextColor(context.getResources().getColor(R.color.light_white_));             
return textView;                            

}

其中i添加形式元素的線性佈局如下

public static LinearLayout createLayoutForClaimQuestion(ClaimQuestion claimQuestion,Context context){ 
LinearLayout linearLayout=new LinearLayout(context);             
LinearLayout.LayoutParams linearLayoutParams=new LinearLayout.LayoutParams(500,200);     
linearLayout.setLayoutParams(linearLayoutParams);             
linearLayout.setOrientation(LinearLayout.VERTICAL);             
TextView questionLabel=createTextView(claimQuestion,context);          
linearLayout.addView(questionLabel,0);                
if (claimQuestion.getQuestionType()==ClaimQuestion.QuestionTypeEnum.CQ_TEXT){      
    EditText editText=createEditText(claimQuestion,context);           
    linearLayout.addView(editText,1);                
}else if(claimQuestion.getQuestionType()==ClaimQuestion.QuestionTypeEnum.CQ_CHECKBOX){    
    CheckBox checkBox=createCheckBox(claimQuestion,context);           
    linearLayout.addView(checkBox,1);                
}else if(claimQuestion.getQuestionType()==ClaimQuestion.QuestionTypeEnum.CQ_SELECT){     
    Spinner spinner=createSpinner(claimQuestion,context);           
    linearLayout.addView(spinner,1);                 
}                         
return linearLayout;                     

}

父佈局的XML佈局文件中給出是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.maximus.mycar.VehicleSelectActivity" 
android:background="@drawable/bluebg_320_568"> 
<include layout="@layout/header" 
    android:id="@+id/top_header_layout_ici" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:layout_marginTop="10dp"/> 
<ScrollView 
    android:id="@+id/claim_questions_scroll_view" 
    android:layout_below="@id/top_header_layout_ici" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:layout_marginBottom="20dp" 
    > 
    <LinearLayout 
     android:id="@+id/claim_questions_linear_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

    </LinearLayout> 
</ScrollView> 

+0

將文本的顏色改爲黑色 – Amy 2014-10-18 11:06:17

+1

您在哪裏添加「textView」? – Rustam 2014-10-18 11:08:39

+0

@AmolTate我試過了,但沒有奏效。 – 2014-10-18 11:09:46

回答

1

我改變了字體大小通過設置固定值,然後它工作正常。

textView.setTextSize(12); 
0

使用這一個: -

textView.setTextColor(getResources().getColor(R.color.light_white_)); 

,而不是這樣的: -

textView.setTextColor(context.getResources().getColor(R.color.light_white_)); 

請讓我還是知道,如果它的工作原理不是:)

+0

我不是在做這個活動。 – 2014-10-18 12:01:24

+0

是片段......? – 2014-10-18 12:02:46

+0

不,它是實用類 – 2014-10-18 12:10:39