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.
Related
I'm getting data from JSON to my object BalanceSheet and want to display the data in a Table layout but Im getting the following error,
The specified child already has a parent. You must call removeView() on the child's parent first.
// on this line
tableLayout.addView(data_row);
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/balance_table_SV"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.BalanceTable">
</ScrollView>
and Activity :
public class BalanceTable extends AppCompatActivity {
ScrollView balance_table_SV;
ArrayList<BalanceSheet> bsList = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_balance_table);
balance_table_SV = findViewById(R.id.balance_table_SV);
bsList = (ArrayList<BalanceSheet>) getIntent().getSerializableExtra("list");
TableLayout tableLayout = new TableLayout(this);
tableLayout.setLayoutParams( new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
tableLayout.setStretchAllColumns(true);
tableLayout.removeAllViews();
int rows = bsList.size();
TableRow headers_row = new TableRow(this);
TableRow data_row = new TableRow(this);
for(int i = -1; i < rows; i ++) {
if (i == -1) {
// need check
headers_row.setLayoutParams( new TableLayout.LayoutParams());
TextView headers = new TextView(this);
headers.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
headers.setGravity(Gravity.LEFT);
headers.setPadding(5, 15, 0, 15);
headers.setText("Inv.#");
headers.setBackgroundColor(Color.parseColor("#f0f0f0"));
headers_row.addView(headers);
tableLayout.addView(headers_row);
}
else {
data_row.setLayoutParams( new TableRow.LayoutParams());
TextView tv1 = new TextView(this);
tv1.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv1.setText(String.valueOf(bsList.get(i).getName()));
TextView tv2 = new TextView(this);
tv2.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv2.setText(String.valueOf(bsList.get(i).getCredit()));
TextView tv3 = new TextView(this);
tv3.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv3.setText(String.valueOf(bsList.get(i).getDebt()));
TextView tv4 = new TextView(this);
tv4.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv4.setText(String.valueOf(bsList.get(i).getCredit()));
data_row.addView(tv1);
data_row.addView(tv2);
data_row.addView(tv3);
data_row.addView(tv4);
}
tableLayout.addView(data_row);
}
balance_table_SV.addView(tableLayout);
}
}
This happen cause you are trying to add the same view multiple times in TableLayout. as you are looping through all of your element you have to recreate the data_row again and again for adding it into the table layout.
else{
TableRow data_row = new TableRow(this);
data_row.setLayoutParams( new TableRow.LayoutParams());
TextView tv1 = new TextView(this);
tv1.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv1.setText(String.valueOf(bsList.get(i).getName()));
TextView tv2 = new TextView(this);
tv2.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv2.setText(String.valueOf(bsList.get(i).getCredit()));
TextView tv3= new TextView(this);
tv3.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv3.setText(String.valueOf(bsList.get(i).getDebt()));
TextView tv4 = new TextView(this);
tv4.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv4.setText(String.valueOf(bsList.get(i).getCredit()));
data_row.addView(tv1);
data_row.addView(tv2);
data_row.addView(tv3);
data_row.addView(tv4);
tableLayout.addView(data_row);
}
the above block will solve the problem as it will create the new object of TableRow every time and add it to TableLayout Object
Explanation:
while adding the table row second time it will generate the error cause we are trying to add the same table row which being attached to a parent in this case we can consider it as table layout which shows the row.
So Why we require to Create the new TableRow object:
A simple answer will be the same view item can not be at the multiple places.
I am not able to put two textview's to the right of ImageView and aligning the date to parent right is also getting difficult for me in dynamic creation. someone who have knowledge on this please help me. Design should be DYNAMIC.
tl = (TableLayout) view.findViewById(R.id.mainLayout);
TableRow row2 = new TableRow(getContext());
row2.setLayoutParams(new TableRow.LayoutParams(200, 230, 280));
TableLayout posterInfoTable = new TableLayout(getContext());
posterInfoTable.setBackgroundResource(R.drawable.whitegrey);
posterInfoTable.setLayoutParams(new TableLayout.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 250));
TableRow posterNameRow = new TableRow(getContext());
TableLayout.LayoutParams lp = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, 30, 0);
posterNameRow.setHorizontalGravity(Gravity.LEFT);
posterNameRow.setLayoutParams(lp);
ImageView posterImage = new ImageView(getContext());
posterImage.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
posterImage.setMaxHeight(100);
posterImage.setMaxWidth(100);
Picasso.with(getContext())
.load(R.drawable.dummyimage2)
.placeholder(R.drawable.dummyimage2)
.error(R.drawable.dummyimage2)
.transform(new RoundedTransformation(50, 4))
.resizeDimen(R.dimen.list_detail_image_size, R.dimen.list_detail_image_size)
.centerCrop()
.into(posterImage);
posterNameRow.addView(posterImage);
final TableRow nameRow = new TableRow(getContext());
nameRow.setPadding(40, 0, 0, 0);
nameRow.setLayoutParams(new TableLayout.LayoutParams(250, 100));
nameRow.setTag(db_id);
TextView posterName = new TextView(getContext());
posterName.setText(postman);
posterName.setTextColor(Color.BLACK);
posterName.setTextSize(18);
posterName.setPadding(10, 0, 0, 0);
posterName.setWidth(240);
// posterName.text
posterNameRow.addView(posterName);
TextView dateview = new TextView(getContext());
dateview.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT))
dateview.setText(date);
dateview.setPadding(50, 0, 0, 5);
dateview.setTextColor(Color.DKGRAY);
dateview.setTextSize(10);
dateview.setWidth(300);
dateview.setGravity(Gravity.RIGHT);
nameRow.addView(dateview);
posterInfoTable.addView(posterNameRow);
posterInfoTable.addView(nameRow);
// posterInfoTable.addView(dateRow);
row2.addView(posterInfoTable, new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 200));
// row2.addView(dateview);
tl.addView(row2, new TableLayout.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 200));
you do not need to create all views dynamically. Create XML with your item-layout. try this:
void addNewRow(YourData data) {
View v = getLayoutInflater().inflate(R.layout.your_item, null);
RelativeLayout rl = (RelativeLayout) v; //or other...
TextView textView1 = (TextView) rl.findViewById(R.id.textV1);
ImageView imageView1 = (ImageView) rl.findViewById(R.id.imageV1);
textView1.setText(data.name);
imageView.setImageResource(data.imageRes);
tableLayout.addView(rl);
}
I'm dynamically creating Table rows and adding two TextViews into the new Rows. Doing that works fine, but now I'm trying to format the LayoutParams so that the two TextViews have a layout_weight of 1 each. I've tried adding some LayoutParams but it looks like they are being ignored. Here's my code for creating the rows, and I've commented out the LayoutParams bit, and there is no change when I run the app, which says to me that the LayoutParams are being ignored. I need some help assigning layout_weight to the two TextViews so that in my row-creating code I can achieve this:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1" />
So here's my code to create the rows:
TableLayout tl = (TableLayout) findViewById(R.id.pres_table);
for (int ctr = 0; ctr < pres_res.size(); ctr++)
{
final String pst_str = pres_res.get(ctr);
final String yrs_str = yrs_res.get(ctr);
TableRow tr = new TableRow(this);
/*
TableRow.LayoutParams trPara = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
int leftMargin = 10;
int topMargin = 2;
int rightMargin = 10;
int bottomMargin = 2;
trPara.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(trPara);
*/
TextView tv1 = new TextView(this);
tv1.setText(pst_str);
tv1.setTextColor(Color.BLACK);
tv1.setTextSize(18);
TextView tv2 = new TextView(this);
tv2.setText(yrs_str);
tv2.setTextColor(Color.BLACK);
tv2.setTextSize(18);
tr.addView(tv1);
tr.addView(tv2);
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
and the XML to create the Table is basic like this:
<TableLayout
android:id="#+id/pres_table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
</TableLayout>
Thanks!
// try this way
TextView tv1 = new TextView(this);
tv1.setLayoutParams(new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
tv1.setText(pst_str);
tv1.setTextColor(Color.BLACK);
tv1.setTextSize(18);
TextView tv2 = new TextView(this);
tv2.setLayoutParams(new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
tv2.setText(yrs_str);
tv2.setTextColor(Color.BLACK);
tv2.setTextSize(18);
tr.addView(tv1);
tr.addView(tv2);
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT));
First, thanks to Geobits for setting me on the right path and letting me know I had the LayoutParams calls in the wrong place. They need to be applied to the TextView, not the Table Row. Then based on that, I found a StackOverflow posting: Set the layout weight of a TextView programmatically where the second answer was the solution for me. So now my code looks like this and it works the way I want it:
TableLayout tl = (TableLayout) findViewById(R.id.pres_table);
for (int ctr = 0; ctr < pres_res.size(); ctr++)
{
final String pst_str = pres_res.get(ctr);
final String yrs_str = yrs_res.get(ctr);
TableRow tr = new TableRow(this);
/*
TableRow.LayoutParams trPara = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
int leftMargin = 10;
int topMargin = 2;
int rightMargin = 10;
int bottomMargin = 2;
trPara.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(trPara);
tr.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
*/
LayoutParams tvPar = new TableRow.LayoutParams(0,LayoutParams.WRAP_CONTENT, 1f);
TextView tv1 = new TextView(this);
tv1.setLayoutParams(tvPar);
tv1.setText(pst_str);
tv1.setTextColor(Color.BLACK);
tv1.setTextSize(18);
TextView tv2 = new TextView(this);
tv2.setLayoutParams(tvPar);
tv2.setText(yrs_str);
tv2.setTextColor(Color.BLACK);
tv2.setTextSize(18);
tr.addView(tv1);
tr.addView(tv2);
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
Right under the commented out bit is the solution showing the new LayoutParams tvPar code.
I have a LinearLayout inside a FrameLayout for tab purposes. And I'm trying to add TableRow's to the LinearLayout in the code.
LinearLayout testLayout = (LinearLayout)findViewById(R.id.testLayout);
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
This gets my LinearLayout and creates a TableRow to the specifications I want. I know this part is working.
TextView textOne = new TextView(this);
textOne.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
textOne.setText("One");
TextView textTwo = new TextView(this);
textTwo.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
textTwo.setText("Two");
Here I make my two TextViews with no problem.
tableRow.addView(textOne);
tableRow.addView(textTwo);
testLayout.addView(tableRow, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
Here is where I assume everything goes wrong. What happens is it only shows the textTwo. I don't know why it's not showing both of them in order like a normal TableRow would in XML. And I repeat, this must be done in code.
Please help, thank you.
Have you imported this import android.widget.TableRow.LayoutParams
Below code works for me
TableLayout tl = (TableLayout) findViewById(R.id.spreadsheet);
TableRow tr = new TableRow(this);
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(lp);
TextView tvLeft = new TextView(this);
tvLeft.setLayoutParams(lp);
tvLeft.setBackgroundColor(Color.WHITE);
tvLeft.setText("OMG");
TextView tvCenter = new TextView(this);
tvCenter.setLayoutParams(lp);
tvCenter.setBackgroundColor(Color.WHITE);
tvCenter.setText("It");
TextView tvRight = new TextView(this);
tvRight.setLayoutParams(lp);
tvRight.setBackgroundColor(Color.WHITE);
tvRight.setText("WORKED!!!");
tr.addView(tvLeft);
tr.addView(tvCenter);
tr.addView(tvRight);
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
I think you want to create your TextView dynamically and should're getting error "removeView () parent." Here is a good solution for that:
TableView tlSkills = (TableView) findViewById(R.id.myTableView);
if(listSkills.size() > 0) {
TableRow tableRow = new TableRow(getContext());
int i = 0;
for (Skills s : listSkills) {
TextView textView = new TextView(getContext());
textView.setText("" + s.getName());
tableRow.addView(textView);
if(i > 0) {
tlSkills.removeView(tableRow);//this is to avoid the error I mentioned above.
}
tlSkills.addView(tableRow);
i++;
}
}
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);
}