I have a piece of code that is parsing my xml values to my android activity, i need to show the parsed xml values in two textviews in horizantal orientation programatically, the values of each textview should be in vertical orientation . I got the textviews in unstructured way. I need to show the text views in structured way. Can anyone please help me to sort out this problem. eg for unstructured output:
flag
false
id
0
I need an output like
flag false
id 0
I created textviews like this
private void createTextView(String text, LinearLayout root, int textSize,
int width, int height, int gravity) {
TextView textView = new TextView(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width,
height);
if (gravity == Gravity.RIGHT) {
params.setMargins(300, 0, 0, 0);
}
if (gravity == Gravity.LEFT) {
params.setMargins(150, 0, 0, 0);
}
if (gravity == Gravity.CENTER) {
params.setMargins(20, 5, 0, 5);
}
textView.setLayoutParams(params);
textView.setText(text);
textView.setTextSize(textSize);
textView.setGravity(params.gravity);
textView.setTextColor(context.getResources().getColor(
android.R.color.black));
root.addView(textView);
}
private void createTextViewsWithHorizontalOrient(String textOne,
String textTwo, LinearLayout root) {
LinearLayout horizontalLinearLayout = new LinearLayout(context);
LinearLayout horizontalNextLinearLayout = new LinearLayout(context);
horizontalLinearLayout.setOrientation(LinearLayout.VERTICAL);
horizontalLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
horizontalNextLinearLayout.setOrientation(LinearLayout.VERTICAL);
horizontalNextLinearLayout
.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
horizontalNextLinearLayout.setGravity(Gravity.TOP);
horizontalLinearLayout.setGravity(Gravity.TOP);
createTextView(textOne, horizontalLinearLayout, 18,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
Gravity.LEFT);
createTextView(textTwo, horizontalNextLinearLayout, 18,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
Gravity.RIGHT);
root.addView(horizontalLinearLayout);
root.addView(horizontalNextLinearLayout);
}
I got the solution in the method create textview change layout params
private void createTextView(String text, LinearLayout root,
int textSize,int width, int height, int gravity) {
TextView textView = new TextView(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100,
height);
createTextView(textTwo, horizontalNextLinearLayout, 18,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
Gravity.LEFT);