Is there any way of generating weight to textviews for linearlayout in java file.
This is the code im using but its not alligned properly
java file:
LinearLayout afternoonLayout = (LinearLayout) findViewById(R.id.afternoonLayoutId);
if(afternoonSession !=null && afternoonSession.size() >= 0){
TextView txtAfternoon = new TextView(this);
txtAfternoon.setText("Afternoon");
txtAfternoon.setTextSize(22);
txtAfternoon.setGravity(Gravity.LEFT);
txtAfternoon.setTypeface(null, Typeface.BOLD);
txtAfternoon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
if(afternoonSession.has("Vitals")){
txtAfternoonVitals = new TextView(this);
txtAfternoonVitals.setText("Vitals " + "- " + " " + afternoonSession.get("Vitals").toString().replace("\"", ""));
txtAfternoonVitals.setTextSize(16);
txtAfternoonVitals.setGravity(Gravity.START);
txtAfternoonVitals.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}else{
txtAfternoonVitals = new TextView(this);
txtAfternoonVitals.setText("Vitals " + "- " + " " + "Not Done");
txtAfternoonVitals.setTextColor(Color.RED);
txtAfternoonVitals.setTextSize(16);
txtAfternoonVitals.setGravity(Gravity.START);
txtAfternoonVitals.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}
if(afternoonSession.has("Lunch")){
txtAfternoonLunch = new TextView(this);
txtAfternoonLunch.setText("Lunch " + "- " + " " + afternoonSession.get("Lunch").toString().replace("\"", ""));
txtAfternoonLunch.setTextSize(16);
txtAfternoonLunch.setGravity(Gravity.START);
txtAfternoonLunch.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}else{
txtAfternoonLunch = new TextView(this);
txtAfternoonLunch.setText("Lunch " + "- " + " " + "Not Done");
txtAfternoonLunch.setTextColor(Color.RED);
txtAfternoonLunch.setTextSize(16);
txtAfternoonLunch.setGravity(Gravity.START);
txtAfternoonLunch.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}
if(afternoonSession.has("Oral Medication")){
txtAfternoonOral = new TextView(this);
txtAfternoonOral.setText("Oral Medication " + "- " + " " + afternoonSession.get("Oral Medication").toString().replace("\"", ""));
txtAfternoonOral.setTextSize(16);
txtAfternoonOral.setGravity(Gravity.START);
txtAfternoonOral.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}else{
txtAfternoonOral = new TextView(this);
txtAfternoonOral.setText("Oral Medication " + "- " + " " + "Not Done");
txtAfternoonOral.setTextColor(Color.RED);
txtAfternoonOral.setTextSize(16);
txtAfternoonOral.setGravity(Gravity.START);
txtAfternoonOral.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}
afternoonLayout.setPadding(10,10,10,10);
afternoonLayout.addView(txtAfternoon);
afternoonLayout.addView(txtAfternoonVitals);
afternoonLayout.addView(txtAfternoonLunch);
afternoonLayout.addView(txtAfternoonOral);
}
I have alligned the code using blankspace, this is not the proper way of doing since im getting different allignment in different mobile versions
Output needed:
Afternoon
vitals 02:00pm
Lunch 03:00pm
Oral Medication 04:00pm
But i am getting unalligned textview in different mobile versions.Is there any way of adding weight to java file.Since im doing string concatination i am unable to use weights
This is the output i am getting