I have putting such data into LinearView. as like below code:
public void showResult()
{
//db.open();
//c2 = db.getAllTitles(table_name);
List<TextView> textListWord = new ArrayList<TextView>(tempEmployerList.size());
List<TextView> textListAnswer = new ArrayList<TextView>(tempEmployerList.size());
List<TextView> imageListAnswer = new ArrayList<TextView>(tempEmployerList.size());
//for(int i = 0; i < c.getCount(); i++)
//int limit = tempEmployerList.size();
for(int i = 0; i<=tempEmployerList.size()-1; i++)
{
RelativeLayout innerLayout = new RelativeLayout(this);
innerLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
innerLayout.setBackgroundColor(0x00000000);
// set the Multiple TextView
TextView qWordTV = new TextView(getApplicationContext());
TextView aWordTV = new TextView(getApplicationContext());
TextView aImageView = new TextView(getApplicationContext());
qWordTV.setText("\n"+"1");
qWordTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
qWordTV.setTextColor(0xFFFF0000);
qWordTV.setPadding(3, 0, 0, 0);
aWordTV.setText("\n"+"2");
aWordTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
aWordTV.setGravity(Gravity.CENTER);
aWordTV.setTextColor(0xFFFF0000);
aWordTV.setGravity(Gravity.CENTER);
aWordTV.setPadding(40, 0, 0, 0);
aWordTV.setTextColor(0xFFFF0000);
aImageView.setText("\n"+"3");
aImageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
aImageView.setGravity(Gravity.RIGHT);
aImageView.setTextColor(0xFF000000);
aImageView.setPadding(0, 0, 9, 0);
/**** Any other text view setup code ****/
innerLayout.addView(qWordTV);
innerLayout.addView(aWordTV);
innerLayout.addView(aImageView);
myLinearLayout.addView(innerLayout);
textListWord.add(qWordTV);
textListAnswer.add(aWordTV);
imageListAnswer.add(aImageView);
}
//while (limit==0);
}
Now i want to create the Simple View dynamicaly here. . .
As like:
<View android:layout_height="2dip" android:background="#FF000000" />
in xml.
Now how to make such View like line dynamicaly ?
Please help me in this.
Thanks.
View line = new View(getApplicationContext());
line.setBackgroundColor(0xFF000000);
// You may need to convert dip to px here, raw pixels are used in the example:
LayoutParams layoutParams = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, 2);
line.setLayoutParams(layoutParams);
Related
I want to build a dynamic table which will have TextView with some content. It could happen that the text is long, in that case, I want my text to be wrapped. But in the code given below it does not work. I tried adding layout parameters to my TextView with weight=1 does not work.
Here is my code:
table = FindViewById<TableLayout>(Resource.Id.main_table);
TableRow tr_head = new TableRow(this);
tr_head.Id = 10;
tr_head.SetBackgroundColor(Color.Gray);
TableRow.LayoutParams paramTableRow = new TableRow.LayoutParams(LayoutParams.MatchParent,
LayoutParams.WrapContent);
tr_head.LayoutParameters = paramTableRow;
LinearLayout.LayoutParams paramcell = new LinearLayout.LayoutParams(LayoutParams.WrapContent,LayoutParams.WrapContent,1.0f);
TextView label_Buyway = new TextView(this);
label_Buyway.Id=20;
label_Buyway.Text ="Buyway";
label_Buyway.SetTextColor(Color.Black);
label_Buyway.SetPadding(5, 5, 5, 5);
tr_head.AddView(label_Buyway);
TextView label_qty = new TextView(this);
label_qty.Id=21;
label_qty.Text="Qty";
label_qty.SetTextColor(Color.Black);
label_qty.SetPadding(5, 5, 5, 5);
tr_head.AddView(label_qty);
TextView label_price = new TextView(this);
label_price.Id = 22;
label_price.Text = "Price";
label_price.SetTextColor(Color.Black);
label_price.SetPadding(5, 5, 5, 5);
tr_head.AddView(label_price);
TextView label_total = new TextView(this);
label_total.Id = 23;
label_total.Text = "Total";
label_total.SetTextColor(Color.Black);
label_total.SetPadding(5, 5, 5, 5);
tr_head.AddView(label_total);
table.AddView(tr_head, new TableLayout.LayoutParams(
LayoutParams.MatchParent,
LayoutParams.WrapContent));
for (int i = 0; i < 10; i++)
{
string date = DateTime.Now.ToString();
Double weight_kg = 1.1;
TableRow tr = new TableRow(this);
tr.Id=(100 + i);
tr.LayoutParameters = paramTableRow;
TextView labelBuyway = new TextView(this);
labelBuyway.Id=(200 + i);
labelBuyway.Text =date;
labelBuyway.SetTextColor(Color.Black);
labelBuyway.SetBackgroundResource(Resource.Drawable.table_row);
labelBuyway.LayoutParameters = paramcell;
tr.AddView(labelBuyway);
TextView labelqty = new TextView(this);
labelqty.Id=(200 + i);
labelqty.Text=(weight_kg.ToString());
labelqty.SetTextColor(Color.Black);
labelqty.SetBackgroundResource(Resource.Drawable.table_row);
tr.AddView(labelqty);
TextView labelPrice = new TextView(this);
labelPrice.Id = (200 + i);
labelPrice.Text = (weight_kg.ToString());
labelPrice.SetTextColor(Color.Black);
labelPrice.SetBackgroundResource(Resource.Drawable.table_row);
tr.AddView(labelPrice);
TextView labelTotal = new TextView(this);
labelTotal.Id = (200 + i);
labelTotal.Text = (weight_kg.ToString());
labelTotal.SetTextColor(Color.Black);
labelTotal.SetBackgroundResource(Resource.Drawable.table_row);
tr.AddView(labelTotal);
table.AddView(tr, new TableLayout.LayoutParams(
LayoutParams.MatchParent,
LayoutParams.WrapContent));
i++;
}
Right now the text gets cut and does not wrap. Any help would be appreciated.
What I guess is these three lines would do the trick :
textViewName.HorizontalScrollBarEnabled = false;
textViewName.SetMinLines(2);
textViewName.InputType = Android.Text.InputTypes.TextFlagMultiLine;
with the weight property set to 1 and these three properties, it should work.
Please revert whether it works.
give your textviews with weight=1 and Wrap content. SO it will expand according to the text size.
I have create a lot of image button like this code:
TableRow tr = new TableRow(this);
if (db != null) {
if (db.moveToFirst()) {
do {
ImageButton button = new ImageButton(this);
int ID = Integer.parseInt(db.getString(db.getColumnIndex("ID")));
int resource = getResources().getIdentifier("unit" + ID, "drawable", getPackageName());
System.out.println("unit" + ID + ":" + resource);
button.setImageResource(resource);
button.setOnClickListener(MainActivity.this);
tr.addView(button);
button.getLayoutParams().height = 250;
button.getLayoutParams().width = 250;
button.setScaleType(ImageView.ScaleType.FIT_CENTER);
//button.setLayoutParams(tableRowParams);
rowcount++;
if (rowcount % 5 == 0) {
layout.addView(tr);
tr = new TableRow(this);
}
} while (db.moveToNext());
}
}
And I found code:
TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
tableRowParams.setMargins(0, 0, 0, 0);
and apply in button at the do while.
button.setLayoutParams(tableRowParams);
It will show the error message "android.widget.TableLayout$LayoutParams cannot be cast to android.widget.TableRow$LayoutParams"
Replace TableLayout.LayoutParams with TableRow.LayoutParams:
TableRow.LayoutParams tableRowParams =
new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT);
tableRowParams.setMargins(0, 0, 0, 0);
The type of LayoutParams that you use is determined by the container of the view, not the view itself. So since your button is going inside a TableRow you need to use TableRow.LayoutParams rather than TableLayout.LayoutParams as you have it now.
Also, just so you're aware, if you need to style your TableRow or Button, rather than creating a new instance of the class and seeing the margins that way, you can inflate an XML layout using Button button = (Button) LayoutInflater.from(context).inflate(R.layout.button, tr, false); and that way you can set the margins in the XML file.
In my application i want to show VIEW ALL to left align like below image:-
But I found this type of layout and more thing i also do all these layout programmatically.
My SourceCode:-
private void printFrontCategory(){
for(int i=0;i<main.size();i++) {
View v = new View(MainActivity.this);
v.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.FILL_PARENT, 5));
v.setBackgroundColor(Color.rgb(51, 51, 51));
/* View v1 = new View(MainActivity.this);
v1.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.FILL_PARENT,5));
v1.setBackgroundColor(Color.rgb(255, 255, 255));*/
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(MainActivity.this);
horizontalScrollView.setHorizontalScrollBarEnabled(false);
TextView textView = new TextView(MainActivity.this);
String content = front_category_catetory_name.get(i);
content = content.replace("'", "");
content = content.replace("&","");
textView.setText(content);
textView.setGravity(Gravity.RIGHT);
// textView.setGravity(Gravity.CENTER);
textView.setTextSize(20);
TextView textView2 = new TextView(MainActivity.this);
textView2.setText("VIEW ALL");
textView2.setTextColor(Color.BLUE);
textView2.setGravity(Gravity.LEFT);
LinearLayout linearLayout2 = new LinearLayout(MainActivity.this);
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
linearLayout2.addView(textView,0);
linearLayout2.addView(textView2,1);
LinearLayout linearLayout = new LinearLayout(MainActivity.this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
for (int j = 0; j < main.get(i).size(); j++) {
LinearLayout linearLayout1 = new LinearLayout(MainActivity.this);
linearLayout1.setOrientation(LinearLayout.VERTICAL);
ImageView image = new ImageView(MainActivity.this);
TextView nameProduct = new TextView(MainActivity.this);
TextView priceProduct = new TextView(MainActivity.this);
TextView special_discount = new TextView(MainActivity.this);
/* Log.d("counter val",cnt+"");
Log.d("thumb ",front_category_thumb.size()+"");
Log.d("image", front_category_thumb.get(52));*/
new SetImageView(image).execute(main.get(i).get(j).get(1));
nameProduct.setText(main.get(i).get(j).get(2));
if (!String.valueOf(main.get(i).get(j).get(5)).equals(null)) {
priceProduct.setText(main.get(i).get(j).get(3));
special_discount.setText(main.get(i).get(j).get(5));
priceProduct.setPaintFlags(nameProduct.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
priceProduct.setGravity(Gravity.CENTER);
special_discount.setGravity(Gravity.CENTER);
nameProduct.setGravity(Gravity.CENTER);
linearLayout1.addView(image);
linearLayout1.addView(nameProduct);
linearLayout1.addView(priceProduct);
linearLayout1.addView(special_discount);
} else if (!String.valueOf(main.get(i).get(j).get(4)).equals(null)) {
priceProduct.setText(main.get(i).get(j).get(3));
special_discount.setText(main.get(i).get(j).get(4));
priceProduct.setPaintFlags(nameProduct.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
priceProduct.setGravity(Gravity.CENTER);
special_discount.setGravity(Gravity.CENTER);
nameProduct.setGravity(Gravity.CENTER);
linearLayout1.addView(image);
linearLayout1.addView(nameProduct);
linearLayout1.addView(priceProduct);
linearLayout1.addView(special_discount);
} else {
priceProduct.setText(main.get(i).get(j).get(3));
priceProduct.setGravity(Gravity.CENTER);
nameProduct.setGravity(Gravity.CENTER);
linearLayout1.addView(image);
linearLayout1.addView(nameProduct);
linearLayout1.addView(priceProduct);
}
linearLayout.addView(linearLayout1, j);
}
horizontalScrollView.addView(linearLayout);
// linearLayoutmens.addView(textView);
// linearLayoutmens.addView(v1);
linearLayoutmens.addView(linearLayout2);
linearLayoutmens.addView(horizontalScrollView);
linearLayoutmens.addView(v);
}
}
I am new in android programming. Please help me!
If you haven't found solution yet, then you can try the following
textView.setGravity(Gravity.RIGHT); This basically act as Gravity for text within TextView for more info refer So basically it is counter part of android:Gravity. Hence we need LayoutParam
Your problem it can be solved in two ways using LinearLayout and RelativeLayout change the below code from
TextView textView = new TextView(MainActivity.this);
String content = front_category_catetory_name.get(i);
content = content.replace("'", "");
content = content.replace("&","");
textView.setText(content);
textView.setGravity(Gravity.RIGHT);
// textView.setGravity(Gravity.CENTER);
textView.setTextSize(20);
TextView textView2 = new TextView(MainActivity.this);
textView2.setText("VIEW ALL");
textView2.setTextColor(Color.BLUE);
textView2.setGravity(Gravity.LEFT);
LinearLayout linearLayout2 = new LinearLayout(MainActivity.this);
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
linearLayout2.addView(textView,0);
linearLayout2.addView(textView2,1);
Solution1 Using LinearLayout
TextView textView = new TextView(MainActivity.this);
String content = front_category_catetory_name.get(i);
content = content.replace("'", "");
content = content.replace("&","");
textView.setText(content);
textView.setGravity(Gravity.START); //Gravity.Left also works
textView.setTextSize(20);
TextView textView2 = new TextView(MainActivity.this);
textView2.setText("VIEW ALL");
textView2.setTextColor(Color.BLUE);
textView2.setGravity(Gravity.END); //Gravity.Right also works
LinearLayout linearLayout2 = new LinearLayout(MainActivity.this);
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams linearLayoutParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,2);
linearLayout2.setLayoutParams(linearLayoutParam);
LinearLayout.LayoutParams viewParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,1);
linearLayout2.addView(textView, 0, viewParam);
linearLayout2.addView(textView2, 1, viewParam);
In above solution I have assigned weightSum = 2 to LinearLayout and weight=1 to each TextView.
Solution2 Using RelativeLayout
TextView textView = new TextView(MainActivity.this);
String content = front_category_catetory_name.get(i);
content = content.replace("'", "");
content = content.replace("&","");
textView.setText(content);
//textView.setGravity(Gravity.START); //Gravity.Left also works
textView.setTextSize(20);
TextView textView2 = new TextView(MainActivity.this);
textView2.setText("VIEW ALL");
textView2.setTextColor(Color.BLUE);
//textView2.setGravity(Gravity.END); //Gravity.Right also works
RelativeLayout relativeLayout2 = new RelativeLayout(MainActivity.this);
RelativeLayout.LayoutParams relativeLayoutParam1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
relativeLayoutParam1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
relativeLayout2.addView(textView, 0, relativeLayoutParam1);
RelativeLayout.LayoutParams relativeLayoutParam2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
relativeLayoutParam2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
relativeLayout2.addView(textView2, 1, relativeLayoutParam2);
In this case textView.setGravity(Gravity.RIGHT); is optional.
Update Based on comment
If you want underlined text as in SAMPLE below then check one of the answer here
<u>Sample</u>
But if you want a black line then it is view and you need to add it after adding linearlayout2 or relativelayout2 depending upon the solution in the main view.
In my table layout i have several rows ,i want to make a horizantal line between them so how can i do it programmatically.
TableLayout resultLayout = new TableLayout(this);
resultLayout.setStretchAllColumns(true);
resultLayout.setShrinkAllColumns(true);
{
// Code to create Registration mark Row
TableRow tableRowRegistrationMark = new TableRow(this);
tableRowRegistrationMark.setGravity(Gravity.CENTER_HORIZONTAL);
TextView textViewRegistartionMark = new TextView(this);
textViewRegistartionMark.setText("Registration mark:");
textViewRegistartionMark.setTextSize(TypedValue.COMPLEX_UNIT_DIP,
12);
textViewRegistartionMark.setTypeface(Typeface.SERIF, Typeface.BOLD);
textViewRegistartionMark.setGravity(Gravity.LEFT);
TextView textViewRegistrationMarkData = new TextView(this);
textViewRegistrationMarkData.setText(strbs[3]);
textViewRegistrationMarkData.setTextSize(
TypedValue.COMPLEX_UNIT_DIP, 12);
textViewRegistrationMarkData.setTypeface(Typeface.SERIF,
Typeface.BOLD);
textViewRegistrationMarkData.setGravity(Gravity.LEFT);
tableRowRegistrationMark.addView(textViewRegistartionMark, 0);
tableRowRegistrationMark.addView(textViewRegistrationMarkData, 1);
// Code to create Make Model Row
TableRow tableRowMakeModel = new TableRow(this);
tableRowMakeModel.setGravity(Gravity.CENTER_HORIZONTAL);
TextView textViewMakeModel = new TextView(this);
textViewMakeModel.setText("Make/Model:");
textViewMakeModel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textViewMakeModel.setTypeface(Typeface.SERIF, Typeface.BOLD);
textViewMakeModel.setGravity(Gravity.LEFT);
TextView textViewMakeModelData = new TextView(this);
textViewMakeModelData.setText(strddss[1]);
textViewMakeModelData.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textViewMakeModelData.setTypeface(Typeface.SERIF, Typeface.BOLD);
textViewMakeModelData.setGravity(Gravity.LEFT);
tableRowMakeModel.addView(textViewMakeModel, 0);
tableRowMakeModel.addView(textViewMakeModelData, 1);
// Code to create RowColour
TableRow tableRowColour = new TableRow(this);
tableRowColour.setGravity(Gravity.CENTER_HORIZONTAL);
TextView textViewColour = new TextView(this);
textViewColour.setText("Colour:");
textViewColour.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textViewColour.setTypeface(Typeface.SERIF, Typeface.BOLD);
textViewColour.setGravity(Gravity.LEFT);
TextView textViewColourData = new TextView(this);
textViewColourData.setText(strddss[2]);
textViewColourData.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textViewColourData.setTypeface(Typeface.SERIF, Typeface.BOLD);
textViewColourData.setGravity(Gravity.LEFT);
tableRowColour.addView(textViewColour, 0);
tableRowColour.addView(textViewColourData, 1);
// Code to create RowChassisNo
TableRow tableRowChasisNo = new TableRow(this);
tableRowChasisNo.setGravity(Gravity.CENTER_HORIZONTAL);
TextView textViewChasisNo = new TextView(this);
textViewChasisNo.setText("VIN/Chassis No:");
textViewChasisNo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textViewChasisNo.setTypeface(Typeface.SERIF, Typeface.BOLD);
textViewChasisNo.setGravity(Gravity.LEFT);
TextView textViewChasisNoData = new TextView(this);
textViewChasisNoData.setText(strddss[3]);
textViewChasisNoData.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textViewChasisNoData.setTypeface(Typeface.SERIF, Typeface.BOLD);
textViewChasisNoData.setGravity(Gravity.LEFT);
tableRowChasisNo.addView(textViewChasisNo, 0);
tableRowChasisNo.addView(textViewChasisNoData, 1);
resultLayout.addView(tableRowRegistrationMark);
resultLayout.addView(tableRowMakeModel);
resultLayout.addView(tableRowColour);
resultLayout.addView(tableRowChasisNo);
resultLayout.addView(tableRowDateofFirstUse);
resultLayout.addView(tableRowTypeofFuel);
}
This is what I use personally.
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="1dp"
android:background="#android:color/darker_gray" />
If you wish to do so programmatically, just create a View with width same as parent and height as desired.
Create a View and Add this View after completing each tablerow
Just put Following code top of the table layout loop
TableLayout.LayoutParams td_tr = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
td_tr.topMargin = GetPixel(1, activityContext);
And
public int GetPixel(float f , Context context)
{
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return (int)((f * displayMetrics.density) + 0.5f);
}
Hope it will help you.
In My application i want to create the layout as like below image:
So How to make it possible ?
I have done Something like below code:
public void showResult()
{
List<TextView> textListWord = new ArrayList<TextView>(tempEmployerList.size());
List<TextView> textListAnswer = new ArrayList<TextView>(tempEmployerList.size());
List<TextView> imageListAnswer = new ArrayList<TextView>(tempEmployerList.size());
for(int i = 0; i<=tempEmployerList.size()-1; i++)
{
LinearLayout innerLayout = new LinearLayout(this);
innerLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
innerLayout.setBackgroundColor(0x00000000);
// set the Multiple TextView
TextView mHeading = new TextView(getApplicationContext());
TextView middleValue = new TextView(getApplicationContext());
TextView aImageView = new TextView(getApplicationContext());
mHeading.setText("\n"+"1");
//mHeading.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
mHeading.setTextColor(0xFFFF0000);
mHeading.setPadding(3, 0, 0, 0);
middleValue.setText("\n"+"2");
//middleValue.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
middleValue.setTextColor(0xFFFF0000);
middleValue.setGravity(Gravity.RIGHT);
middleValue.setPadding(2, 0, 9, 0);
aImageView.setText("\n"+"3");
//aImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
aImageView.setGravity(Gravity.RIGHT);
aImageView.setTextColor(0xFF000000);
aImageView.setPadding(0, 0, 9, 0);
View line = new View(getApplicationContext());
//line.setOrientation(1);
line.setLayoutParams(new LayoutParams(2, android.view.ViewGroup.LayoutParams.FILL_PARENT));
line.setBackgroundColor(0xFF000000);
/**** Any other text view setup code ****/
innerLayout.addView(mHeading);
innerLayout.addView(middleValue);
innerLayout.addView(aImageView);
innerLayout.addView(line);
myLinearLayout.addView(innerLayout);
textListWord.add(mHeading);
textListAnswer.add(middleValue);
imageListAnswer.add(aImageView);
}
}
So please guide me that what more i have to do to create such view ?
Thanks.
try TableLayout and TableRow instead of LinearLayout.
You can create TableLayout in xml as well, as it, I think would be static and add TableRows. To Create a TableLayout in Java use,
TableLayout tblLayout=new TableLayout(this);
Set LayoutParams and other properties of table layout in java, like I am setting LayoutParams:
LayoutParams params=new LayoutParams(LayoutParams.Fill_Parent, LayoutParams.Wrap_Content);
tblLayout.setLayoutParams(params);
Create a loop for TableRows creation and insertion:
for(int i=0;i<arrList1.size();i++)
{
TableRow row=new TableRow(this);
row.setLayoutParams(params);
TextView lbl1=new TextView(this);
lbl1.setText(arrList1.get(i));
row.addView(lbl1);
TextView lbl2=new TextView(this);
lbl2.setText(arrList2.get(i));
row.addView(lbl2);
TextView lbl3=new TextView(this);
lbl3.setText(arrList3.get(i));
row.addView(lbl3);
tblLayout.addView(row);
}