I have created a table layout in which my table row height is too small, so I want to increase the height of the table row , please guide me table is dynamically created so I don't have any idea.
Code: I have tried to specify width in Latoutparam integer but not working
public void createTableLayout()
{
String status="Pending";
TextView txtid=(TextView)findViewById(R.id.txtcid);
//TextView txtdate=(TextView)findViewById(R.id.txtDate);
txtid.setText("Customer Id/Name : "+shopnum+"/"+shopname1);
btnorder1=(Button)findViewById(R.id.btnOrder123);
btnBack1=(Button)findViewById(R.id.btnBack1);
txtTotalAmount=(TextView)findViewById(R.id.txtTotalAmt);
btnorder1.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
ShowcOrder1();
int rcount=(table).getChildCount();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String currentDateandTime = sdf.format(new Date());
for(int r=1;r<rcount;r++)
{
TableRow row=(TableRow)table.getChildAt(r);
int vcount=(row).getChildCount();
// String str=
for(int v1=0;v1<vcount;v1++)
{
TextView tv = (TextView)(((TableRow)row)).getChildAt(v1);
insertIntoOrderDetails(String.valueOf(orderid),ProdcutId,PackageId,Quantity);
}
insertIntoOrder(String.valueOf(orderid), currentDateandTime, shopnum,String.valueOf(roundtotal), sid);
Toast.makeText(getApplicationContext(), "Order Placed",Toast.LENGTH_LONG).show();
finish();
// Toast.makeText(getApplicationContext(), "round: "+roundtotal,Toast.LENGTH_LONG).show();
}
});
btnBack1.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
finish();
}
});
//txtdate.setText("Order Date is : "+odate);
table = (TableLayout) findViewById(R.id.tbpastorderdetails);
TableRow tr_heading = new TableRow(Pastorder.this);
tr_heading.setId(10);
tr_heading.setBackgroundColor(Color.BLACK);
tr_heading.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView label_product_id = new TextView(Pastorder.this);
label_product_id.setId(20);
label_product_id.setText("PID");
label_product_id.setTextColor(Color.WHITE);
//label_question.setPadding(2, 2, 2, 2);
// label_date.setPadding(5, 5, 5, 5);
tr_heading.addView(label_product_id); // add the column to the table row
//TextView label_question = new TextView(this);
TextView label_package_id = new TextView(Pastorder.this);
label_package_id.setId(20);
label_package_id.setText(" Pack.ID");
label_package_id.setTextColor(Color.WHITE);
//label_question.setPadding(2, 2, 2, 2);
// label_date.setPadding(5, 5, 5, 5);
tr_heading.addView(label_package_id); // add the column to the table row
//TextView label_question = new TextView(this);
TextView label_product = new TextView(Pastorder.this);
label_product.setId(20);
label_product.setText(" PRODUCT");
label_product.setTextColor(Color.WHITE);
//label_question.setPadding(2, 2, 2, 2);
// label_date.setPadding(5, 5, 5, 5);
tr_heading.addView(label_product); // add the column to the table row
// here
// Toast.makeText(ExaminationActivity.this,"hi try ",Toast.LENGTH_LONG).show();
//TextView label_answer = new TextView(this);
TextView label_catagory = new TextView(Pastorder.this);
label_catagory.setId(21);// define id that must be unique
label_catagory.setText(" CATAGORY"); // set the text for the header
label_catagory.setTextColor(Color.WHITE); // set the color
// label_weight_kg.setPadding(5, 5, 5, 5); // set the padding (if
// required)
// label_weight_kg.setPadding(2, 2, 2, 2);
tr_heading.addView(label_catagory); // add the column to the table row
// here
//TextView label_youranswer = new TextView(this);
TextView label_package = new TextView(Pastorder.this);
label_package.setId(20);
label_package.setText(" PACKAGE");
label_package.setTextColor(Color.WHITE);
//label_question.setPadding(2, 2, 2, 2);
// label_date.setPadding(5, 5, 5, 5);
tr_heading.addView(label_package); // add the column to the table row
// here
TextView label_weight = new TextView(Pastorder.this);
label_weight.setId(20);
label_weight.setText(" WEIGHT");
label_weight.setTextColor(Color.WHITE);
//label_question.setPadding(2, 2, 2, 2);
// label_date.setPadding(5, 5, 5, 5);
tr_heading.addView(label_weight); // add the column to the table row
TextView label_qty = new TextView(Pastorder.this);
label_qty.setId(20);
label_qty.setText(" QUANTITY");
label_qty.setTextColor(Color.WHITE);
//label_question.setPadding(2, 2, 2, 2);
// label_date.setPadding(5, 5, 5, 5);
tr_heading.addView(label_qty); // add the column to the table row
TextView label_amt = new TextView(Pastorder.this);
label_amt.setId(20);
label_amt.setText(" AMOUNT");
label_amt.setTextColor(Color.WHITE);
//label_question.setPadding(2, 2, 2, 2);
// label_date.setPadding(5, 5, 5, 5);
tr_heading.addView(label_amt); // add the column to the table row
table.addView(tr_heading, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
public void addRows()
{
try
{
msaledb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
Cursor allrows = msaledb.rawQuery("SELECT * FROM " + PRODUCT_TABLE+" WHERE Product_ID = '" + pid +"'", null);
Cursor allrows1 = msaledb.rawQuery("SELECT * FROM " + PACKAGING_TABLE ,null);
if(allrows.moveToFirst() && allrows1.moveToFirst())// && allrows1.moveToFirst())
{
int i=1;
do
{
tr = new TableRow(Pastorder.this);
tr.setId(i);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView tvpid = new TextView(Pastorder.this);
tvpid.setId(11);
tvpid.setText(""+pid);
tvpid.setPadding(2, 0, 5, 0);
tvpid.setTextColor(Color.BLACK);
tr.addView(tvpid);
TextView tv_pack_id = new TextView(Pastorder.this);
tv_pack_id.setId(12);
tv_pack_id.setText(" "+packid);
tv_pack_id.setPadding(2, 0, 5, 0);
tv_pack_id.setTextColor(Color.BLACK);
tr.addView(tv_pack_id);
TextView tv = new TextView(Pastorder.this);
tv.setId(1);
tv.setText(" "+allrows.getString(2));
tv.setPadding(2, 0, 5, 0);
tv.setTextColor(Color.BLACK);
tr.addView(tv);
TextView tv1 = new TextView(Pastorder.this);
tv1.setId(2);
tv1.setText(" "+allrows.getString(3));
tv1.setPadding(2, 0, 5, 0);
tv1.setTextColor(Color.BLACK);
tr.addView(tv1);
do
{
if(allrows1.getString(1).trim().equals(packid.trim()) && allrows1.getString(2).trim().equals(pid.trim()))
{
// Toast.makeText(getApplicationContext(), ""+allrows1.getString(2).trim(),Toast.LENGTH_LONG).show();
// Toast.makeText(getApplicationContext(), ""+p_id.get(0).trim(),Toast.LENGTH_LONG).show();
TextView tv2 = new TextView(Pastorder.this);
tv2.setId(3);
tv2.setText(" "+allrows1.getString(3));
tv2.setPadding(2, 0, 5, 0);
tv2.setTextColor(Color.BLACK);
tr.addView(tv2);
TextView tv3 = new TextView(Pastorder.this);
tv3.setId(4);
tv3.setText(" "+allrows1.getString(4));
tv3.setPadding(2, 0, 5, 0);
tv3.setTextColor(Color.BLACK);
tr.addView(tv3);
TextView tv4 = new TextView(Pastorder.this);
tv4.setId(4);
tv4.setText(" "+qty);
tv4.setPadding(2, 0, 5, 0);
tv4.setTextColor(Color.BLACK);
tr.addView(tv4);
TextView tv5 = new TextView(Pastorder.this);
tv5.setId(4);
tv5.setText(" "+Integer.parseInt(allrows1.getString(6).trim())*Integer.parseInt(qty.trim()));
tv5.setPadding(2, 0, 5, 0);
tv5.setTextColor(Color.BLACK);
tr.addView(tv5);
}
}while(allrows1.moveToNext());
table.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
i++;
tr.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
view.setBackgroundColor(Color.LTGRAY);
// Toast.makeText(getApplicationContext(),""+tr.getId(),Toast.LENGTH_LONG).show();
tr1=(TableRow)view; //assign selected TableRow gobally
registerForContextMenu(tr1);
openContextMenu(tr1);
}
});
}while(allrows.moveToNext());
}
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Error in search", Toast.LENGTH_LONG).show();
}
}
The TableRow layout parameters must be wrap content. Instead of trying to expand the row in order to fit your needs, try to manually set the appropriate layout parameters in the views that are inside the TableRow object. Wrap content or fill parent won't work, try playing around with actual density pixels.
Hope this helps
Related
I have created a table containing dynamic table rows. Each table row contain 5 textview containing data's like region name ,regioncode ,target etc. I have implemented a table row OnclickListner,So a user can select the table row to view more specific data in another activity. The problem is each table row Contain must diffrent regionCode to be passed to another activity. How could we pass this to another activity.I tried using string array but it show null point exception.
This is my code
// IF BRANCHFLAG IS ZONAL
else if(branchFlag.equals("Z"))
{
final List<NameValuePair> details = new ArrayList<NameValuePair>(1);
details.add(new BasicNameValuePair("branchCode", branchCode));
details.add(new BasicNameValuePair("branchFlag", branchFlag));
details.add(new BasicNameValuePair("finYr",finyear));
details.add(new BasicNameValuePair("month", month_number));
Log.d("month_num", month_number);
response = apc.postURL(RETRIEVE_BRANCH_MIS_DETAILS_LINK, details);
Log.d("**************", RETRIEVE_BRANCH_MIS_DETAILS_LINK + details);
Log.d("RETRIEVE_MainMis_DETAILS_LINK", response);
try {
JSONObject jsonObject = new JSONObject(response);
jsonArray = jsonObject.getJSONArray("result");
errorflag = jsonObject.getString("errorFlag");
errormsg = jsonObject.getString("errorMsg");
if (errorflag.equals("N"))
{
// adding 4 data sections to the table row
TextView label_product = new TextView(MainMis.this);
label_product.setId(0);
label_product.setText(" Region ");
label_product.setTextColor(Color.WHITE);
tr_head.addView(label_product);// add the column to the table row here
TextView label_target = new TextView(MainMis.this);
label_target.setId(0);// define id that must be unique
label_target.setText(" Target "); // set the text for the header
label_target.setTextColor(Color.WHITE); // set the color
label_target.setPadding(5, 5, 5, 5);
label_target.setGravity(5); // set the padding (if required)
// label_target.setWidth(10);
tr_head.addView(label_target); // add the column to the table row here
TextView label_achievement = new TextView(MainMis.this);
label_achievement.setId(0);
label_achievement.setText(" Achievement");
label_achievement.setTextColor(Color.WHITE);
label_achievement.setPadding(5, 5, 5, 5);
label_achievement.setGravity(5);
// label_achievement.setWidth(50);
tr_head.addView(label_achievement);
TextView label_shortfall = new TextView(MainMis.this);
label_shortfall.setId(0);
label_shortfall.setText(" Shortfall");
label_shortfall.setTextColor(Color.WHITE);
label_shortfall.setPadding(5, 5, 5, 5);
label_shortfall.setGravity(5);
// label_achievement.setWidth(50);
tr_head.addView(label_shortfall);
TextView label_ranking = new TextView(MainMis.this);
label_ranking.setId(0);
label_ranking.setText(" Ranking ");
label_ranking.setTextColor(Color.WHITE);
label_ranking.setPadding(5, 5, 5, 5);
label_ranking.setGravity(5);
tr_head.addView(label_ranking);
// add the table row the the main table layout that we fetched at the start
tl.addView(tr_head, new TableLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
TextView[] textArray = new TextView[jsonArray.length()];
TableRow[] tr_head1 = new TableRow[jsonArray.length()];
try {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);// set as you need
int i = 0;
int j = 0;
for (i = 0; i < jsonArray.length(); i++)
{
JSONObject jsonobj = jsonArray.getJSONObject(i);
// JSONObject productData = product.getJSONObject("Product");
// String productDescription = product.getString("achievementPer");
DecimalFormat df = new DecimalFormat("#");
incomeAmount = ((jsonobj.getString("AchievementSum")));
excShort = ((jsonobj.getString("excShort")));
String excShort1 = excShort.replace(",", ".");
Double excShort2 = Double.parseDouble(excShort1);
Log.d("excShort, replace ,", excShort1);
Log.d("excShort in point format,", excShort1);
targetAmount = ((jsonobj.getString("targetSum")));
//ADDED BY SOORAJ
Regions = ((jsonobj.getString("regionName")));
zoneName=((jsonobj.getString("zonalName")));
Log.d("achievementPer123", String.valueOf((((excShort)))));
//Create the tablerows
tr_head1[i] = new TableRow(MainMis.this);
tr_head1[i].setClickable(true);
tr_head1[i].setId(i + 1);
if ((i % 2) == 0) {
tr_head1[i].setBackgroundColor(Color.LTGRAY);
} else {
Resources resource = getApplicationContext().getResources();
tr_head1[i].setBackgroundColor(resource.getColor(R.color.white_overlay));
}
// tr_head1[i++].setBackgroundColor(Color.YELLOW);
tr_head1[i].setLayoutParams(new TableLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
// Here create the TextView dynamically
textArray[i] = new TextView(MainMis.this);
//Modified
//
textArray[i].setId(i + 111);
textArray[i].setText(" " + Regions);
textArray[i].setTextColor(Color.BLACK);
textArray[i].setPadding(5, 5, 5, 5);
tr_head1[i].addView(textArray[i]);
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(targetAmount));
textArray[i].setTextColor(Color.BLACK);
// textArray[i].setWidth(10);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(5);
tr_head1[i].addView(textArray[i]);
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(incomeAmount));
textArray[i].setTextColor(Color.BLACK);
// textArray[i].setWidth(10);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(5);
tr_head1[i].addView(textArray[i]);
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(excShort ));
if (excShort2 > 0) {
textArray[i].setTextColor(Color.BLUE);
} else {
textArray[i].setTextColor(Color.RED);
}
// textArray[i].setWidth(120);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(5);
tr_head1[i].addView(textArray[i]);
//ADDED BRANCH RANKING
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(Rgn_Ranking));
textArray[i].setTextColor(Color.BLACK);
// textArray[i].setWidth(10);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(Gravity.CENTER|Gravity.BOTTOM);
tr_head1[i].addView(textArray[i]);
tl.setVisibility(View.VISIBLE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
if (tr_head1.length > 0)
{
tl.addView(tr_head1[i], new TableLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
length = String.valueOf(tr_head1.length);
Log.d("LENGTH OF ARRAY", String.valueOf(length));
//Make the table row onClickable
tr_head1[i].setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent a=new Intent(MainMis.this,RegionMIS.class);
Bundle extras = a.getExtras();
startActivity(a);
}
});
}
}
if ((i == 0)) {
Log.d("No rows to display **", "");
tl.setVisibility(View.GONE);
l2.setVisibility(View.VISIBLE);
l3.setVisibility(View.GONE);
//Toast.makeText(MainMis.this, "No data to display", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
Log.d("ERROR...", e.getMessage().toString());
}
} else {
tl.setVisibility(View.GONE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
l4.setVisibility(View.VISIBLE);
errormsgedit.setText(errormsg);
}
} catch (Exception ex) {
ex.printStackTrace();
Log.d("ERROR...ERROR..", ex.getMessage().toString());
}
}
The simplest way to do this is like this
Intent intent = new Intent(MainMis.this, RegionMIS.class);
intent.putExtra("EXTRA_REGION_CODE", regionCode);
startActivity(intent)
I got the answer.. i created one more textview with its visiblity as GONE
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(regionBrCode));
textArray[i].setTextColor(Color.BLACK);
// textArray[i].setWidth(10);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(5);
textArray[i].setVisibility(View.GONE);
tr_head1[i].addView(textArray[i]);
Then i added this in onClick listner of the table row
{
#Override
public void onClick(View v)
{
v.setBackgroundColor(Color.RED);
String t=String.valueOf(v.getId());
Log.d("ROW CLICKED : ",t);
// get the table clicked
TableRow tablerow = (TableRow)tl.getChildAt(v.getId());
TextView sample = (TextView) tablerow.getChildAt(5);
String result=sample.getText().toString();
Log.d("RegionCode",result);
Intent a=new Intent(MainMis.this,RegionMIS.class);
a.putExtra("regionCode",result);
}
});
I want to get index or id of clicked row in TableLayout. Some of the codes looks:
final TableRow rows = new TableRow(this);
rows.setClickable(true);
Click action of the button, which adds rows to TableLayout
TableRow row = new TableRow(getApplicationContext());
row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
row.setTag(String.valueOf(queue_number));
row.setClickable(true);
if (queue_number % 2 == 0) {
row.setBackgroundColor(getResources().getColor(R.color.blue_grey));
} else {
row.setBackgroundColor(getResources().getColor(R.color.white));
}
TextView row_queue = new TextView(Satish.this);
row_queue.setText(String.valueOf(queue_number));
row_queue.setPadding(6, 6, 0, 6);
TextView row_product_name = new TextView(Satish.this);
row_product_name.setText(product_name.getText().toString());
row_product_name.setPadding(0, 6, 0, 6);
TextView row_unit_of_measurement = new TextView(Satish.this);
row_unit_of_measurement.setText(unit_of_measurement.getText().toString());
row_unit_of_measurement.setPadding(0, 6, 0, 6);
TextView row_price = new TextView(Satish.this);
row_price.setText(price.getText().toString());
row_price.setPadding(0, 6, 0, 6);
TextView row_sum = new TextView(Satish.this);
row_sum.setText(sum.getText().toString());
row_sum.setPadding(0, 6, 0, 6);
row.addView(row_queue);
row.addView(row_product_name);
row.addView(row_unit_of_measurement);
row.addView(row_price);
row.addView(row_sum);
root_table.addView(row);
queue_number++;
And in the click event of rows looks:
rows.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), String.valueOf(v.getId()), LENGTH_LONG).show();
// client_name.setText(String.valueOf(rows.getChildAt(1)));
// TableRow t = (TableRow) v.getParent();
// Toast.makeText(getApplicationContext(), String.valueOf(t.getId()), LENGTH_LONG).show();
// for (int id = 0; id < root_table.getChildCount(); id++) {
// if (v.getId() == id) {
// Toast.makeText(Satish.this, String.valueOf(r[0].getId()), LENGTH_LONG).show();
// }
// }
}
});
But this event returns just nothing. I don't know what's the wrong in my codes. I couldn't see mistake.
Any helpful comment/answer appreciated.
P.S I have searched out in the internet about this, but couldn't found the correct solution for this problem. But, maybe this question is possibly duplicate.
Edit
I can replace field rows with row. If I do it there'll be only one TableRow element. So code looks like:
final TableRow row = new TableRow(getApplicationContext());
row.setClickable(true);
Click action of the button, which adds rows to TableLayout
row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
row.setTag(String.valueOf(queue_number));
row.setClickable(true);
if (queue_number % 2 == 0) {
row.setBackgroundColor(getResources().getColor(R.color.blue_grey));
} else {
row.setBackgroundColor(getResources().getColor(R.color.white));
}
TextView row_queue = new TextView(Satish.this);
row_queue.setText(String.valueOf(queue_number));
row_queue.setPadding(6, 6, 0, 6);
TextView row_product_name = new TextView(Satish.this);
row_product_name.setText(product_name.getText().toString());
row_product_name.setPadding(0, 6, 0, 6);
TextView row_unit_of_measurement = new TextView(Satish.this);
row_unit_of_measurement.setText(unit_of_measurement.getText().toString());
row_unit_of_measurement.setPadding(0, 6, 0, 6);
TextView row_price = new TextView(Satish.this);
row_price.setText(price.getText().toString());
row_price.setPadding(0, 6, 0, 6);
TextView row_sum = new TextView(Satish.this);
row_sum.setText(sum.getText().toString());
row_sum.setPadding(0, 6, 0, 6);
row.addView(row_queue);
row.addView(row_product_name);
row.addView(row_unit_of_measurement);
row.addView(row_price);
row.addView(row_sum);
root_table.addView(row);
queue_number++;
In this situation some design problems occur in TableLayout.
I found the best solution for my problem.
I moved the following lines from inside of onCreate() to button click event:
final TableRow row = new TableRow(getApplicationContext());
row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
row.setId(Integer.valueOf(String.valueOf(queue_number)));
row.setClickable(true);
if (queue_number % 2 == 0) {
row.setBackgroundColor(getResources().getColor(R.color.blue_grey));
} else {
row.setBackgroundColor(getResources().getColor(R.color.white));
}
TextView row_queue = new TextView(Satish.this);
row_queue.setText(String.valueOf(queue_number));
row_queue.setPadding(6, 6, 0, 6);
TextView row_product_name = new TextView(Satish.this);
row_product_name.setText(product_name.getText().toString());
row_product_name.setPadding(0, 6, 0, 6);
TextView row_unit_of_measurement = new TextView(Satish.this);
row_unit_of_measurement.setText(unit_of_measurement.getText().toString());
row_unit_of_measurement.setPadding(0, 6, 0, 6);
TextView row_price = new TextView(Satish.this);
row_price.setText(price.getText().toString());
row_price.setPadding(0, 6, 0, 6);
TextView row_sum = new TextView(Satish.this);
row_sum.setText(sum.getText().toString());
row_sum.setPadding(0, 6, 0, 6);
row.addView(row_queue);
row.addView(row_product_name);
row.addView(row_unit_of_measurement);
row.addView(row_price);
row.addView(row_sum);
root_table.addView(row/*, queue_number*/);
// set onClickListener at runtime. This is working well for me.
root_table.getChildAt(queue_number).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TableRow tr = (TableRow) v;
TextView num, p_n, u_o_m, p, s;
// num = (TextView) tr.getChildAt(0);
p_n = (TextView) tr.getChildAt(1);
u_o_m = (TextView) tr.getChildAt(2);
p = (TextView) tr.getChildAt(3);
s = (TextView) tr.getChildAt(4);
// row_id = Integer.getInteger(num.getText().toString());
product_name.setText(p_n.getText().toString());
unit_of_measurement.setText(u_o_m.getText().toString());
price.setText(p.getText().toString());
sum.setText(s.getText().toString());
}
});
queue_number++;
hi in the below I am fetching the data from database and getting the json response and displaying in an android table layout.But everything was working fine but i want to put some sub headings for displaying data for that I took the textview In that using setText() I am giving sub heading.But it's not displaying proper heading.
this output when I am running my app:
General registration
SI Date Toatal Registration
1 2015-04-01 2
2 2015-04-02 3
1 2015-04-02 3
Expected output:
SI Date Toatal Registration
General registration
1 2015-04-01 2
2 2015-04-02 3
Ipd registration
1 2015-04-02 3
java
public class Datewise_Patient_list extends Activity {
String data = "",result="";
TableLayout tl;
TableRow tr;
TextView si,tv;
String queryString;
int numOfPatients = 0;
TextView[] snos;
TextView[] date;
TextView[] tot_reg;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.datewise_collection_report);
tl = (TableLayout) findViewById(R.id.maintable);
tv=(TextView)findViewById(R.id.tv);
final String date1 = getIntent().getStringExtra("date1");
final String date2 = getIntent().getStringExtra("date2");
new Thread(new Runnable() {
public void run() {
queryString = "date1=" + date1 + "&date2="
+ date2;
data = DatabaseUtility.executeQueryPhp("DateWise_Collection_report",queryString);
System.out.println(data);
runOnUiThread(new Runnable() {
#Override
public void run() {
ArrayList<DateWise_Patients> datewisepatients = parseJSON(data);
numOfPatients = datewisepatients.size();
addData(datewisepatients);
}
});
}
}).start();
new Thread(new Runnable() {
public void run() {
queryString = "date1=" + date1 + "&date2="
+ date2;
result = DatabaseUtility.executeQueryPhp("DateWise_ipd_report",queryString);
System.out.println(result);
runOnUiThread(new Runnable() {
#Override
public void run() {
ArrayList<DateWise_Patients> datewiseipdpatients = parseJSON1(result);
numOfPatients = datewiseipdpatients.size();
addData1(datewiseipdpatients);
}
});
}
}).start();
}
public ArrayList<DateWise_Patients> parseJSON(String data) {
ArrayList<DateWise_Patients> datewisepatients = new ArrayList<DateWise_Patients>();
try {
JSONArray jArray = new JSONArray(data);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
DateWise_Patients datewisepatient = new DateWise_Patients();
datewisepatient.setDate(json_data.getString("date"));
datewisepatient.setTot_reg(json_data.getString("total"));
datewisepatients.add(datewisepatient);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return datewisepatients;
}
public ArrayList<DateWise_Patients> parseJSON1(String result) {
ArrayList<DateWise_Patients> datewiseipdpatients = new ArrayList<DateWise_Patients>();
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
DateWise_Patients datewiseipdpatient = new DateWise_Patients();
datewiseipdpatient.setDate(json_data.getString("date"));
datewiseipdpatient.setTot_reg(json_data.getString("total"));
datewiseipdpatients.add(datewiseipdpatient);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return datewiseipdpatients;
}
void addHeader(){
/** Create a TableRow dynamically **/
tr = new TableRow(this);
/** Creating a TextView to add to the row **/
si = new TextView(this);
si.setText("SI");
si.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
si.setPadding(5, 5, 5, 5);
LinearLayout Ll = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(5, 5, 5, 5);
Ll.addView(si,params);
tr.addView((View)Ll); // Adding textView to tablerow.
/** Creating Qty Button **/
TextView date = new TextView(this);
date.setText("Date");
date.setTextSize(15);
date.setTextColor(Color.parseColor("#FFA500"));
date.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
date.setPadding(5, 5, 5, 5);
// pat_name.setBackgroundColor(Color.parseColor("#075E93"));
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 5, 5, 5);
//Ll.setPadding(10, 5, 5, 5);
Ll.addView(date,params);
tr.addView((View)Ll); // Adding textview to tablerow.
/** Creating Qty Button **/
TextView tot_reg = new TextView(this);
tot_reg.setText("Total Registrations");
tot_reg.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tot_reg.setPadding(5, 5, 5, 5);
//reg_date.setBackgroundColor(Color.parseColor("#075E93"));
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 5, 5, 5);
//Ll.setPadding(10, 5, 5, 5);
Ll.addView(tot_reg,params);
tr.addView((View)Ll); // Adding textview to tablerow.
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
#SuppressWarnings({ "rawtypes", "deprecation" })
public void addData(ArrayList<DateWise_Patients> datewisepatients) {
snos = new TextView[numOfPatients];
date = new TextView[numOfPatients];
tot_reg=new TextView[numOfPatients];
int j = 0;
addHeader();
tv.setText("General Registration");
for (Iterator i = datewisepatients.iterator(); i.hasNext();) {
snos[j] = (TextView) findViewById(R.id.si);
date[j] = (TextView) findViewById(R.id.date);
tot_reg[j]=(TextView)findViewById(R.id.tot_reg);
DateWise_Patients p = (DateWise_Patients) i.next();
/** Create a TableRow dynamically **/
tr = new TableRow(this);
if(j % 2==0){
tr.setBackgroundColor(Color.parseColor("#00BFFF"));
}
else{
tr.setBackgroundColor(Color.parseColor("#FFFFE0"));
}
/** Creating a TextView to add to the row **/
snos[j] = new TextView(this);
int temp = j;
snos[j].setText(String.valueOf(temp +1));
snos[j].setId(j);
snos[j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
snos[j].setPadding(5, 5, 5, 5);
// snos[j].setBackgroundColor(Color.GRAY);
LinearLayout Ll = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(5, 2, 2, 2);
Ll.setPadding(10, 5, 5, 5);
Ll.addView(snos[j],params);
tr.addView((View)Ll); // Adding textView to tablerow.
/** Creating Qty Button **/
date[j] = new TextView(this);
date[j].setKeyListener(null);
date[j].setText(p.getDate());
date[j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
date[j].setPadding(5, 5, 5, 5);
// patNames[j].setBackgroundColor(Color.GRAY);
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 2, 2, 2);
//Ll.setPadding(10, 5, 5, 5);
Ll.addView(date[j],params);
tr.addView((View)Ll); // Adding textview to tablerow.
/** Creating Qty Button **/
tot_reg[j] = new TextView(this);
tot_reg[j].setKeyListener(null);
tot_reg[j].setText(p.getTot_reg());
tot_reg[j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tot_reg[j].setPadding(5, 5, 5, 5);
// regdates[j].setBackgroundColor(Color.GRAY);
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 2, 2, 2);
//Ll.setPadding(10, 5, 5, 5);
Ll.addView(tot_reg[j],params);
tr.addView((View)Ll); // Adding textview to tablerow.
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
j++;
}
}
#SuppressWarnings({ "rawtypes", "deprecation" })
public void addData1(ArrayList<DateWise_Patients> datewiseipdpatients) {
snos = new TextView[numOfPatients];
date = new TextView[numOfPatients];
tot_reg=new TextView[numOfPatients];
int j = 0;
// tv.setText("Ipd Patient List");
for (Iterator i = datewiseipdpatients.iterator(); i.hasNext();) {
snos[j] = (TextView) findViewById(R.id.si);
date[j] = (TextView) findViewById(R.id.date);
tot_reg[j]=(TextView)findViewById(R.id.tot_reg);
DateWise_Patients p = (DateWise_Patients) i.next();
/** Create a TableRow dynamically **/
tr = new TableRow(this);
if(j % 2==0){
tr.setBackgroundColor(Color.parseColor("#00BFFF"));
}
else{
tr.setBackgroundColor(Color.parseColor("#FFFFE0"));
}
/** Creating a TextView to add to the row **/
snos[j] = new TextView(this);
int temp = j;
snos[j].setText(String.valueOf(temp +1));
snos[j].setId(j);
snos[j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
snos[j].setPadding(5, 5, 5, 5);
// snos[j].setBackgroundColor(Color.GRAY);
LinearLayout Ll = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(5, 2, 2, 2);
Ll.setPadding(10, 5, 5, 5);
Ll.addView(snos[j],params);
tr.addView((View)Ll); // Adding textView to tablerow.
/** Creating Qty Button **/
date[j] = new TextView(this);
date[j].setKeyListener(null);
date[j].setText(p.getDate());
date[j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
date[j].setPadding(5, 5, 5, 5);
// patNames[j].setBackgroundColor(Color.GRAY);
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 2, 2, 2);
//Ll.setPadding(10, 5, 5, 5);
Ll.addView(date[j],params);
tr.addView((View)Ll); // Adding textview to tablerow.
/** Creating Qty Button **/
tot_reg[j] = new TextView(this);
tot_reg[j].setKeyListener(null);
tot_reg[j].setText(p.getTot_reg());
tot_reg[j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tot_reg[j].setPadding(5, 5, 5, 5);
// regdates[j].setBackgroundColor(Color.GRAY);
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 2, 2, 2);
//Ll.setPadding(10, 5, 5, 5);
Ll.addView(tot_reg[j],params);
tr.addView((View)Ll); // Adding textview to tablerow.
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
j++;
}
}
I have a TableLayout and fill it with a WebService and it's Works fine, but when I want to execute the second time the WebService, the data show it below the previous, I have to clean before show a new information, how can do that?
The code onTaskComplete and showTablaPos(fill TableLayOut)
// Called after task finished
#Override
public void onTaskComplete(JSONObject result) {
// TODO Auto-generated method stub
try{
ljsonObject = result;
//Se obtienen los valores de status y mensaje
int status = ljsonObject.getInt("status");
String mensaje = ljsonObject.getString("mensaje");
mensaje = mensaje.concat(", favor de llamar a la oficina de tú cancha para reportar este mensaje, gracias");
//status = 0 para el Web Service de Obtener catálogo de Torneos, status = 1 para obtener la tabla de posiciones
try {
ljsonArray = ljsonObject.getJSONArray(tag);
//Arma y carga la tabla de Posiciones
showTablaPos();
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
}catch (Exception e) {
e.printStackTrace();
}
}
public void showTablaPos(){
TableLayout tablaPos = (TableLayout) findViewById(R.id.tabla_pos);
//Create table row header
TableRow tr_head = new TableRow(this);
tr_head.setId(10);
tr_head.setBackgroundColor(Color.GRAY);
//tr_head.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
//Se crean los header
TextView label_equipo = new TextView(this);
label_equipo.setId(20);
label_equipo.setText("EQUIPO");
label_equipo.setTextColor(Color.WHITE);
label_equipo.setPadding(5, 5, 5, 5);
tr_head.addView(label_equipo);
TextView label_jj = new TextView(this);
label_jj.setId(20);
label_jj.setText("JJ");
label_jj.setTextColor(Color.WHITE);
label_jj.setPadding(5, 5, 5, 5);
tr_head.addView(label_jj);
TextView label_jg = new TextView(this);
label_jg.setId(20);
label_jg.setText("JG");
label_jg.setTextColor(Color.WHITE);
label_jg.setPadding(5, 5, 5, 5);
tr_head.addView(label_jg);
TextView label_je = new TextView(this);
label_je.setId(20);
label_je.setText("JE");
label_je.setTextColor(Color.WHITE);
label_je.setPadding(5, 5, 5, 5);
tr_head.addView(label_je);
TextView label_jp = new TextView(this);
label_jp.setId(20);
label_jp.setText("JP");
label_jp.setTextColor(Color.WHITE);
label_jp.setPadding(5, 5, 5, 5);
tr_head.addView(label_jp);
TextView label_gf = new TextView(this);
label_gf.setId(20);
label_gf.setText("GF");
label_gf.setTextColor(Color.WHITE);
label_gf.setPadding(5, 5, 5, 5);
tr_head.addView(label_gf);
TextView label_ge = new TextView(this);
label_ge.setId(20);
label_ge.setText("GE");
label_ge.setTextColor(Color.WHITE);
label_ge.setPadding(5, 5, 5, 5);
tr_head.addView(label_ge);
TextView label_dif = new TextView(this);
label_dif.setId(20);
label_dif.setText("DIF");
label_dif.setTextColor(Color.WHITE);
label_dif.setPadding(5, 5, 5, 5);
tr_head.addView(label_dif);
TextView label_ptos = new TextView(this);
label_ptos.setId(20);
label_ptos.setText("PTOS.");
label_ptos.setTextColor(Color.WHITE);
label_ptos.setPadding(5, 5, 5, 5);
tr_head.addView(label_ptos);
tablaPos.addView(tr_head, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
Integer count = 0;
Integer cuantos = ljsonArray.length();
try{
for (int i = 0; i < ljsonArray.length(); i++) {
ljsonObject = ljsonArray.getJSONObject(i);
String equipo = (ljsonObject.optString("equ_nombre"));
Integer jj = (ljsonObject.optInt("jj"));
Integer jg = (ljsonObject.optInt("jg"));
Integer je = (ljsonObject.optInt("je"));
Integer jp = (ljsonObject.optInt("jp"));
Integer gf = (ljsonObject.optInt("gf"));
Integer ge = (ljsonObject.optInt("ge"));
Integer dif = (ljsonObject.optInt("dif"));
Integer pto = (ljsonObject.optInt("puntos"));
TableRow tr = new TableRow(this);
if(count%2!=0) tr.setBackgroundColor(Color.GRAY);
tr.setId(100+count);
//tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
//Create columns to add as table data
// Create a TextView to add equipo
TextView labelEquipo = new TextView(this);
labelEquipo.setId(200+count);
labelEquipo.setText(equipo);
labelEquipo.setPadding(2, 0, 5, 0);
labelEquipo.setTextColor(Color.WHITE);
tr.addView(labelEquipo);
TextView labelJj = new TextView(this);
labelJj.setId(200+count);
labelJj.setText(Integer.toString(jj));
labelJj.setPadding(2, 0, 5, 0);
labelJj.setTextColor(Color.WHITE);
labelJj.setGravity(Gravity.CENTER);
tr.addView(labelJj);
TextView labelJg = new TextView(this);
labelJg.setId(200+count);
labelJg.setText(Integer.toString(jg));
labelJg.setPadding(2, 0, 5, 0);
labelJg.setTextColor(Color.WHITE);
labelJg.setGravity(Gravity.CENTER);
tr.addView(labelJg);
TextView labelJe = new TextView(this);
labelJe.setId(200+count);
labelJe.setText(Integer.toString(je));
labelJe.setPadding(2, 0, 5, 0);
labelJe.setTextColor(Color.WHITE);
labelJe.setGravity(Gravity.CENTER);
tr.addView(labelJe);
TextView labelJp = new TextView(this);
labelJp.setId(200+count);
labelJp.setText(Integer.toString(jp));
labelJp.setPadding(2, 0, 5, 0);
labelJp.setTextColor(Color.WHITE);
labelJp.setGravity(Gravity.CENTER);
tr.addView(labelJp);
TextView labelGf = new TextView(this);
labelGf.setId(200+count);
labelGf.setText(Integer.toString(gf));
labelGf.setPadding(2, 0, 5, 0);
labelGf.setTextColor(Color.WHITE);
labelGf.setGravity(Gravity.CENTER);
tr.addView(labelGf);
TextView labelGe = new TextView(this);
labelGe.setId(200+count);
labelGe.setText(Integer.toString(ge));
labelGe.setPadding(2, 0, 5, 0);
labelGe.setTextColor(Color.WHITE);
labelGe.setGravity(Gravity.CENTER);
tr.addView(labelGe);
TextView labelDif = new TextView(this);
labelDif.setId(200+count);
labelDif.setText(Integer.toString(dif));
labelDif.setPadding(2, 0, 5, 0);
labelDif.setTextColor(Color.WHITE);
labelDif.setGravity(Gravity.CENTER);
tr.addView(labelDif);
TextView labelPtos = new TextView(this);
labelPtos.setId(200+count);
labelPtos.setText(Integer.toString(pto));
labelPtos.setPadding(2, 0, 5, 0);
labelPtos.setTextColor(Color.WHITE);
labelPtos.setGravity(Gravity.CENTER);
tr.addView(labelPtos);
// finally add this to the table row
tablaPos.addView(tr, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
count++;
}
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
}
}
try to call this function before fill data
private void deleteRows(){
TableLayout tablaPos = (TableLayout) findViewById(R.id.tabla_pos);
tablaPos.removeAllViews();
}
UPDATE:
try this
private void deleteRows(){
TableLayout tablaPos = (TableLayout) findViewById(R.id.tabla_pos);
for(int i = 0; i < tablaPos.getChildCount(); i++){
tablaPos.removeViewAt(i);
}
}
I have a table layout with table rows building according to data given by JSON. I want to highlight a row after pressing it but I need that only one row to be highlighted in every given time, it means that if I highlight a row and then press another row the last row should be highlighted and the first row should not. Everything is working fine but I can't get a row to not be highlighted after it became highlighted. This is my code:
TableLayout tv = (TableLayout) findViewById(R.id.tblFrnd);
tv.removeAllViewsInLayout();
int flag = 1;
for (int i = -1; i < ans.length(); i++) {
TableRow tr = new TableRow(AddFriend.this);
tr.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
if (flag == 1) {
TextView b3 = new TextView(AddFriend.this);
b3.setText("Display Name");
b3.setTextColor(Color.BLUE);
b3.setTextSize(20);
b3.setPadding(10, 0, 0, 0);
tr.addView(b3);
TextView b4 = new TextView(AddFriend.this);
b4.setPadding(50, 0, 0, 0);
b4.setTextSize(20);
b4.setText("User Name");
b4.setTextColor(Color.BLUE);
tr.addView(b4);
TextView b5 = new TextView(AddFriend.this);
b5.setPadding(90, 0, 0, 0);
b5.setTextSize(20);
b5.setText("ID");
b5.setVisibility(View.INVISIBLE);
b5.setTextColor(Color.BLUE);
tr.addView(b5);
tv.addView(tr);
final View vline = new View(AddFriend.this);
vline.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
vline.setBackgroundColor(Color.BLUE);
tv.addView(vline);
flag = 0;
} else {
JSONObject json_data = ans.getJSONObject(i);
TextView b = new TextView(AddFriend.this);
String str = json_data.getString("DisplayName");
b.setText(str);
b.setPadding(10, 0, 0, 0);
b.setTextColor(Color.RED);
b.setTextSize(15);
tr.addView(b);
TextView b1 = new TextView(AddFriend.this);
b1.setPadding(50, 0, 0, 0);
b1.setTextSize(15);
String str1 = json_data.getString("UserName");
b1.setText(str1);
b1.setTextColor(Color.RED);
tr.addView(b1);
final TextView b2 = new TextView(AddFriend.this);
b2.setPadding(90, 0, 0, 0);
b2.setTextSize(15);
String str2 = String.valueOf(json_data.getInt("UserID"));
b2.setText(str2);
b2.setVisibility(View.INVISIBLE);
b2.setTextColor(Color.RED);
tr.addView(b2);
tr.setClickable(true);
tr.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
v.setBackgroundColor(getResources().getColor(R.color.Yellow));
}
});
tv.addView(tr);
final View vline1 = new View(AddFriend.this);
vline1.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
vline1.setBackgroundColor(Color.WHITE);
tv.addView(vline1);
}
Thank you in advance!
Take int selectedRow = -1 in class.
Add a function in the class:
private void updateHighlightedRow()
{
// loop through the rows and set the background
// for a row to highlighted color if the row index == selectedRow
// else sent normal bg color
}
While adding row, make the row clickable and in click listener set row index to selectedRow, then call updateHighlightedRow
This should do the things.
make the textview setClickable(false).