我创建了包含问题文本和适合提问的输入字段的表单。我的表单中有微调,编辑文本和复选框。 所有都是使用活动动态创建的。创建的布局中的问题是输入字段正确显示,但不显示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>
将文本的颜色改为黑色 – Amy 2014-10-18 11:06:17
您在哪里添加“textView”? – Rustam 2014-10-18 11:08:39
@AmolTate我试过了,但没有奏效。 – 2014-10-18 11:09:46