I have a function who gets a list of products from a webpage, and I want to add a row in a tableLayout for each element of the list.
public void getProductsOfCategory() throws IOException{
new Thread(){
public void run(){
//background code...
try {
Bundle extras = getIntent().getExtras();
String categoryName = extras.getString("categoryName");
HttpGet httpget = new HttpGet("http://romal.hopto.org/foodadvisor/users/getProductsOfCategory.json?category="+categoryName);
HttpResponse httpresp = httpClient.execute(httpget);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
httpresp.getEntity().writeTo(baos);
final String content = new String(baos.toByteArray());
CategoryActivity.this.runOnUiThread(new Runnable(){
public void run(){
//foreground code (UI)
//update user interface, for example, showing messages
try {
JSONObject jObject = new JSONObject(content);
JSONArray productsList = jObject.getJSONArray("response");
for(int i=0; i<productsList.length();i++){
JSONObject product = productsList.getJSONObject(i);
JSONObject productData = product.getJSONObject("Product");
String productDescription = productData.getString("description");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
In my layout xml file I have defined the table layout like this:
<TableLayout
android:id="#+id/tableOfProducts"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/productDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:paddingBottom="7dp"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingTop="7dp"
android:textSize="20dp" />
</TableLayout>
I imagine I have to add some extra code in the for loop, adding a new row and a new textview for each element, and setting the content of the text view with the string that has the description of the product.
How can I do this?
Check this out, this is the general way of creating table rows dynamically. Modify it accordingly
XML file
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_table"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</TableLayout>
JAVA PART
TableLayout t1;
TableLayout tl = (TableLayout) findViewById(R.id.main_table);
Create table row header to hold the column headings
TableRow tr_head = new TableRow(this);
tr_head.setId(10);
tr_head.setBackgroundColor(Color.GRAY); // part1
tr_head.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
I'm adding two data sections to the table row
TextView label_hello = new TextView(this);
label_hello.setId(20);
label_hello.setText("HELLO");
label_hello.setTextColor(Color.WHITE); // part2
label_hello.setPadding(5, 5, 5, 5);
tr_head.addView(label_hello);// add the column to the table row here
TextView label_android = new TextView(this); // part3
label_android.setId(21);// define id that must be unique
label_android.setText("ANDROID..!!"); // set the text for the header
label_android.setTextColor(Color.WHITE); // set the color
label_android.setPadding(5, 5, 5, 5); // set the padding (if required)
tr_head.addView(label_android); // add the column to the table row here
After adding the columns to the table row its time to add the table row the the main table layout that we fetched at the start
tl.addView(tr_head, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, //part4
LayoutParams.MATCH_CONTENT));
EDIT : YOU CAN DO THE FOLLOWING IN YOUR CODE
TextView[] textArray = new TextView[productsList.length()];
TableRow[] tr_head = new TableRow[productsList.length()];
for(int i=0; i<productsList.length();i++){
JSONObject product = productsList.getJSONObject(i);
JSONObject productData = product.getJSONObject("Product");
String productDescription = productData.getString("description");
//Create the tablerows
tr_head[i] = new TableRow(this);
tr_head[i].setId(i+1);
tr_head[i].setBackgroundColor(Color.GRAY);
tr_head[i].setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
textArray[i] = new TextView(this);
textArray[i].setId(i+111);
textArray[i].setText(productDescription);
textArray[i].setTextColor(Color.WHITE);
textArray[i].setPadding(5, 5, 5, 5);
tr_head[i].addView(textArray[i]);
// Add each table row to table layout
tl.addView(tr_head[i], new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
} // end of for loop
Creating the TextView and TableRow array are not necessary. You can just include part1, part2, part3 (if you need more than 1 field) and part4 inside your for loop.
Look, i think you have to modify your xml to adding rows to your tableview:
First, the inflater:
LayoutInflater inflater = mContext.getLayoutInflater();
or in this way:
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Here you can set up the layoutparameters from your tableview and the rowview.
//Maybe you don't have to modify nothing from the parameters of your tableview so
//you can dismiss it.
TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
//Here were we take the tablelayout from your xml
TableLayout tableLayout = (TableLayout)inflater.inflate(R.layout.tableOfProducts, null);
//Like a told you before, maybe you don't need set the parameters of the tablelayout
//so you can comment next line.
tableLayout.setLayoutParams(this.tableParams);
TableRow tableRow = new TableRow(context);
tableRow.setLayoutParams(this.tableParams);
//Here you have to create and modify the new textview.
TextView textView = new TextView(context);
textView.setLayoutParams(this.rowParams);
tableRow.addView(textView);
tableLayout.addView(tableRow);
If you need more help, tell me, if it is helpful, rating me!!! ;) Un saludo Gallega! O como se dice en gallego: una aperta!
for this, you have to create one xml file for row, then you have to modify your layout.xml file like
<ScrollView>
<LinearLayout orientation=vertical id="+id/rowHolder">
</LinearLayout
</scrollview>
Then in for loop, inflate the row layout and add it runtime to rowHolder object.
I'm new myself to Android, and after years with Python/Gtk, I'm lost if I can't think in terms of Model/View/Presenter.
one useful approach I managed to apply, it puts me back into that optics, and even if it's not relative to a Table, I'm quite sure it can be extended to that (I guess this page would be a good start, for me too).
start by declaring the two objects in your fragment (or activity):
List<String> stringList; // think of it as the model.
ArrayAdapter<String> listAdapter; // and this would be the presenter
define the model in the fragment constructor:
stringList = new ArrayList<>();
next, when the onCreateView of my fragment is invoked, I do this (edit correspondingly if you're using Activity, not Fragment):
View rootView = inflater.inflate(R.layout.fragment_taxonomy, container, false);
ListView mainListView = rootView.findViewById(R.id.taxonomy_results);
// Create ArrayAdapter using the string list. think of it as the presenter.
// see how it's being handled a model and a view.
listAdapter = new ArrayAdapter<>(
rootView.getContext(), R.layout.textrow, stringList);
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter( listAdapter );
textrow.xml is an extra layout which is being reused every time I add an element to the stringList model.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
in the rest of the code, I only "talk" to listAdapter, and I only need its two add and clear methods, to add elements, or for clearing the list.
There are many ways to do this. First, for minimizing your code, create an XML file that initializes the TableRow and its attribute (TextView should be also included). Then, in your target XML file that is linked to the activity, you have to create only the TableLayout.
In the main, create LayoutInflater that will link the items to gather. Then, create as much as you can of the number of TableRow. In the end, each TableRow that has a unique variable should be linked using addView() to the TableLayout that you have created in the XML.
For more, see here. https://github.com/AreejTurky/Dynamic-TableRow-Generation
Related
I'm designing an app which will accept user input into a TableLayout . The table has 4 headings . I'm unsure of how to get the data into the table . I have a successfully added a test piece of code but I can only add it once. I've attached the code below.
What I wish to know is how to get this to add more than one line to the table?
public void addNew(){
TableLayout tL = (TableLayout)findViewById(R.id.table);
TableRow tR = new TableRow(getApplicationContext());
TextView tV = new TextView(getApplicationContext());
tV.setTextColor(0xff000000);
tV.setText("TEST");
TextView tV2 = new TextView(getApplicationContext());
tV2.setTextColor(0xff000000);
tV2.setText("TEST");
TextView tV3 = new TextView(getApplicationContext());
tV3.setTextColor(0xff000000);
tV3.setText("TEST");
TextView tV4 = new TextView(getApplicationContext());
tV4.setTextColor(0xff000000);
tV4.setText("TEST");
tR.addView(tV);
tR.addView(tV2);
tR.addView(tV3);
tR.addView(tV4);
tL.addView(tR);
}
for (/* x rows */)
{
tL.addView(tR);
}
This should work but if you run into an issue with text view id's clashing you can create an array of text views and an array of table rows. Would make managing and creating them easier as well.
If you make them in an array by doing something like this.
TextView[] textViewArray = new TextView[textViewCount];
for(int i = 0; i < textViewCount; i++)
{
textViewArray[i] = new TextView(this);
}
then you would be able to handle individual values by doing something like this.
textViewArray[i].setText(/* This stuff */);
I am consrtucting a registration form in table layout for which I have to add various textviews in a table row one one below another.
You can get something like this:
Here is the code, you can get the basic idea.
// <table>
TableLayout table = new TableLayout(context);
// <row1>
TableRow row = new TableRow(context);
// <column1>
LinearLayout container = new LinearLayout(context);
container.setBackgroundColor(Color.parseColor("#ff0000"));
container.setOrientation(LinearLayout.VERTICAL);
container.addView(getSampleTextView("Stacked TextView 1", "#ff0000"));
container.addView(getSampleTextView("Stacked TextView 2", "#ffff00"));
row.addView(container);
// </column1>
// <column2>
row.addView(getSampleTextView("TextView in Another Column", "#ffffff"));
// </column2>
table.addView(row);
// </row1>
// <row2>
TableRow row2 = new TableRow(context);
row2.setBackgroundColor(Color.parseColor("#00ffff"));
row2.addView(getSampleTextView("TextView in Next Row", "#0000ff"));
table.addView(row2);
// </row2>
Here is how I get sample text view for demo purposes:
private TextView getSampleTextView(String text, String color) {
TextView textView = new TextView(getContext());
setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setText(text);
textView.setBackgroundColor(Color.parseColor(color));
return textView;
}
Hello I set values in ArrayList Now how can I store that values in different textviews.
For Example:
ArrayList<String> mylist =new ArrayList<String>();
for(int i=0;i<mylist.size();i++)
{
//Here mylist contains 10 values and I have 10 different textviews. Now How can i add values 1 to 10 in different textview. set value to First textview 1,second textview to 2 etc.
}
Please Help me to find this.
This is the way::
TextView []tv=new TextView[10];
tv[0]=(TextView)findViewById(R.id.____);
tv[1]=(TextView)findViewById(R.id.____);
tv[2]=(TextView)findViewById(R.id.____);
tv[3]=(TextView)findViewById(R.id.____);
tv[4]=(TextView)findViewById(R.id.____);
tv[5]=(TextView)findViewById(R.id.____);
tv[6]=(TextView)findViewById(R.id.____);
tv[7]=(TextView)findViewById(R.id.____);
tv[8]=(TextView)findViewById(R.id.____);
tv[9]=(TextView)findViewById(R.id.____);
for(int i=0;i<mylist.size();i++)
{
tv[i].setText(mylist.get(i));
}
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
ArrayList<String> mylist = new ArrayList<String>();
mylist.add("1");
mylist.add("2");
mylist.add("3");
mylist.add("4");
LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
for (int i = 0; i < mylist.size(); i++)
{
TextView tv = new TextView(this);
tv.setLayoutParams(lparams);
tv.setText(mylist.get(i));
layout.addView(tv);
}
And XML File
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
If u have the same no of text views and the data then create a array of views then use for loop as:
ArrayList<String> mylist =new ArrayList<String>();
mylist.add("1st");
mylist.add("2nd");
mylist.add("3rd");
mylist.add("4th");
// mylist.add("5th");
one=(TextView)findViewById(R.id.textView1);
two=(TextView)findViewById(R.id.textView2);
three=(TextView)findViewById(R.id.textView3);
four=(TextView)findViewById(R.id.textView4);
ArrayList<TextView>text=new ArrayList<TextView>(Arrays.asList(one,two,three,four));
for(int i=0;i<mylist.size();i++)
{
text.get(i).setText(mylist.get(i));
//Here mylist contains 10 values and I have 10 different textviews. Now How can i add values 1 to 10 in different textview. set value to First textview 1,second textview to 2 etc.
}
Then you dont need of for loop. just set text to Your text views manually
as
ArrayList<String> mylist =new ArrayList<String>();
TextView txt1 = (TextView)findviewbyId(R.id.txt1);
txt1.setText(mylist.get(0);
....//upto 10 textViews
TextView txt10 = (TextView)findviewbyId(R.id.txt10);
txt10.setText(mylist.get(9);
You could try something like this:
for(int i=0;i<mylist.size();i++)
{
TextView tv = findViewById(getResources().getIdentifier("textView"+i, "id",getPackageName()));
tv.setText(mylist.get(i));
}
I'm not sure that is you want to do. I used the getIdentifier method to retrieve your textViews.
Else, you can inflate your textViews in a loop:
for(int i=0;i<mylist.size();i++)
{
TextView tv = (TextView)LayoutInflater.from(context).inflate(R.layout.myTextView, null);
tv.setText(mylist.get(i));
}
Hope this will help you
You dont need loop here
you need to call textView.setText(mylist.get(0)); ... u need to call this for 10 times with increasing value in get method.. and with diff text view instances.
Edit :as par your comment: here suppose you have created
TextView [] tv; // you need to initialized array here with textviews
ArrayList<String> mylist =new ArrayList<String>();
for(int i=0;i<mylist.size();i++)
{
tv[i].setText(mylist.get(i));
}
for(int i=0;i<mylist.size();i++)
{
tv[i].setText(mylist.get(i));
}
I have a JSON String returned by my web service as follows:
{"checkrecord"[{"rollno":"abc2","percentage":40,"attended":12,"missed":34}],"Table1":[]}
The above String represents my dataset. I have converted the String to a JSON Object and I now want to put the data in the String into a TableLayout.
I want the table to be like this when displayed on android app:
rollno percentage attended missed
abc2 40 12 34
This is the code I am using as of now :
//json processing code
public void jsonprocessing(String c)
{
try
{
JSONObject jsonobject = new JSONObject(c);
JSONArray array = jsonobject.getJSONArray("checkrecord");
int max = array.length();
for (int j = 0; j < max; j++)
{
JSONObject obj = array.getJSONObject(j);
JSONArray names = obj.names();
for (int k = 0; k < names.length(); k++)
{
name = names.getString(k);
value= obj.getString(name);
createtableLayout();
}
}
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//create table layout
public void createtableLayout()
{
Log.d("values",value); //I am able to see the values abc2,40,12 and 34 over here in logcat
TableLayout t= (TableLayout)findViewById(R.id.tablelayout);
TableRow r1=new TableRow(this);
r1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView t1 = new TextView(this);
t1.setText(value);
t1.setTextColor(Color.BLACK);
t1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
r1.addView(t1);
t.addView(r1, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
My TableLayout contains a button and a EditText as the first TableRow. After I click the button I get the JSON String. So I need to insert 2 TableRows dynamically after that as per my requirement.
My xml as of now is as follows:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tablelayout"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#000044">
<TableRow>
<EditText
android:id="#+id/edittext"
android:width="200px" />
<Button
android:id="#+id/button"
android:text="Check Record"/>
</TableRow>
</TableLayout>
So my problem is how to add those 2 extra TableRows so as to populate them with the String values ?
My code isn't working fine. I am not able to get the required output.
Can anyone help me in this?
Thanks
you can use multicolumn listview for your purpose,
Parse the JSON response and get values into different strings and use this blog for your purpose
Multicolumn Listview
You, probably, can define those 2 more rows in your XML and make them initially invisible. Then upon receiving your data put your data in those rows and make them visible.
// Every UI object must have a layout parameter
int widthContent = RelativeLayout.LayoutParams.WRAP_CONTENT;
int heightContent = RelativeLayout.LayoutParams.WRAP_CONTENT;
// Create relative layout
RelativeLayout.LayoutParams rlParamsName = new RelativeLayout.LayoutParams(widthContent,heightContent);
// Create table row layout
int trWidthContent = TableRow.LayoutParams.WRAP_CONTENT;
int trHeightContent = TableRow.LayoutParams.WRAP_CONTENT;
TableRow.LayoutParams trLayout = new TableRow.LayoutParams(trWidthContent, trHeightContent);
// Create a linear layout to add new object as vertical
LinearLayout objLinearLayout = new LinearLayout(context);
objLinearLayout.setOrientation(LinearLayout.VERTICAL);
// Add number of categories to menu
for (int i = 0; i < SpecialCategories.length(); i++) {
try {
// Json for special categories
JSONObject jsonData = SpecialCategories.getJSONObject(i);
// Get name and count of category
String specialCategoryNames = jsonData.getString("label").toString();
String specialCategoryCount = jsonData.getString("coupon_count").toString();
final TableRow tr = new TableRow(this);
tr.setLayoutParams(trLayout);
tr.setId(i);
//tr.setBackgroundColor(0xFFBEBEBE);
// What is the text view for category name
TextView categoryName = new TextView(this);
categoryName.setPadding(8, 8, 8, 8);
categoryName.setTextSize(18);
categoryName.setLayoutParams(trLayout);
categoryName.setText(specialCategoryNames);
categoryName.setId(i);
categoryName.setTypeface(null, Typeface.BOLD);
categoryName.setTextColor(0xFF000000);
// What is count for category
TextView categoryCount = new TextView(this);
categoryCount.setPadding(7, 8, 8, 8);
categoryCount.setLayoutParams(trLayout);
categoryCount.setBackgroundColor(Color.WHITE);
categoryCount.setText("("+specialCategoryCount+")");
// Add disclosure image to row
ImageView objDrawLineImageView = new ImageView(this);
objDrawLineImageView.setPadding(280, 19, 6, 6);
objDrawLineImageView.setImageResource(R.drawable.disclosure);
objDrawLineImageView.setLayoutParams(trLayout);
// Add name of category
tr.addView(categoryName);
// Add count for category
tr.addView(categoryCount);
// Add disclosure back to table row
tr.addView(objDrawLineImageView);
// Add table row into linear layout
objLinearLayout.addView(tr);
//Add Row End Line to Linear layout
ImageView rowEndLine = new ImageView(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,2);
params.setMargins(0, 5, 0, 0);
rowEndLine.setLayoutParams(params);
rowEndLine.setBackgroundColor(0xFFBEBEBE);
// Add end line image to linear layout
objLinearLayout.addView(rowEndLine);
// What happen when user click on table row
tr.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(Main.this, ""+tr.getId(),Toast.LENGTH_SHORT).show();
Log.e("TAG", " clicked ID: "+tr.getId());
}
});
} catch (Exception e) {
e.printStackTrace();
}// end try
}// end for SpecialCategories.length()
//Add button number two to the activity.
RelativeLayout objRelativeLayout = (RelativeLayout)findViewById(R.id.row_special);
objRelativeLayout.addView(objLinearLayout);
I'm still new in android programming, what I'm trying to do is, I want to create 5x5 dimension TableLayout. I know this can be done by using GridView BaseAdapter suing Inflate service. But for this one i try to apply using table layout. Below is the code. I create new instance of TableLayout, and new instance of Table row. On each table row, I created instance of 5 TextView. But once I open in emulator or in my phone, there is no TableRow created, it just empty blank Table Layout. Also there is no exception was thrown.
GridView navIcon = (GridView) findViewById(R.id.content);
navIcon.setAdapter(new ImageAdapter(this));
navIcon.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
// TODO Auto-generated method stub
if (position==0){
try{
TableLayout calgrid = (TableLayout) findViewById(R.id.gridtable);
Context ctxt = v.getContext();
TextView[] tView = new TextView[25];
calgrid = new TableLayout(ctxt);
int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,(float) 1, getResources().getDisplayMetrics());
int counter=1;
TableRow[] tr = new TableRow[5];
for(int j=0;j<5;j++){
tr[j] = new TableRow(ctxt);
for(int i=0;i<5;i++){
tView[i] = new TextView(ctxt);
tView[i].setText(String.valueOf(counter));
tView[i].setTextSize(15);
counter+=1;
tView[i].setWidth(50 * dip);
tView[i].setPadding(20*dip, 0, 0, 0);
tView[i].setTextColor(Color.rgb( 100, 200, 200));
Toast.makeText(getApplicationContext(), "tView["+i+"] value " + String.valueOf(tView[i].getText()), Toast.LENGTH_SHORT).show();
tr[j].addView(tView[i], 50, 50);
}
calgrid.addView(tr[j]);
}
}catch(Exception e){
Log.e("MainActivity", "Error in activity", e);
Toast.makeText(getApplicationContext(),e.getClass().getName() + " " + e.getMessage(),Toast.LENGTH_LONG).show();
}
}
}
});
First of all, it is a mistake to do calgrid = (TableLayout) findViewById(R.id.gridtable); and then calgrid = new TableLayout(ctxt);, which basically says find this view now assign this variable to something completely different. Remove the second statement and it will load the table from xml which is what you want.
Second, I think it would be a good idea to simplify things for yourself because there is a lot going on here. Instead of doing all this work inside an onClick listener, do it in the onCreate method itself. Also, you seem to be using the Context from the GridView, which seems odd. Perhaps if you posted your xml layout file it could help explain what you are trying to do?
There is also a problem with indices in the array of TextViews, as tView[i] will only assign items up to 5 but the array contains 25 items. Try using tView[(j*5)+i] instead. I don't think this is causing your problems but just make sure you are assigning your items correctly.
Here is an example of how to do something along the lines of what you want
setContentView(R.layout.grid);
TableLayout tl = (TableLayout) findViewById(R.id.gridtable);
for (int j = 0; j < 5; j++) {
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
for (int i = 0; i < 5; i++) {
TextView tView = new TextView(this);
tView.setText("TEXT" + String.valueOf((j * 5) + i + 1));
tView.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tr.addView(tView);
}
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
and grid.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridtable"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
Once you get it working in the activity itself you can try to put it inside a listener attached to a GridView. Hope this helps!