How to set table row values descending in order

  • Replies:5
  • OpenNot stickiedAnswered
  • Forum posts: 10

Mar 20, 2021, 2:46:05 PM via Website

I am creating dynamic TableView which includes 3 columns and rows as per my input value entered. The value will display on the first column as per the input entered.

My table row will be updated like

0
20
40
60
80
100
Etc...

My code is

stk.addView(tbrow0);
for (int i = 0; i < input1 / input2 + 1; i++) {
    TableRow tbrow = new TableRow(this);
    TextView t1v = new TextView(this);
    t1v.setText("" + i * input2);
    t1v.setTextColor(Color.BLACK);
    t1v.setGravity(Gravity.CENTER);
    t1v.setTextSize(12);            
    t1v.setBackgroundResource(R.drawable.border);
    tbrow.addView(t1v);

I want to display the values in descending order (High to low) in the first column.

100
80
60
40
20
0

I don't know how to modify my code. Pls guide me

Reply
Best answer
  • Forum posts: 1,387

Mar 23, 2021, 2:05:08 AM via Website

Senthil Kumar.P

Yes this is android studio project.

Both input 1 and input 2 are integers.
Example:
Input1 = 1000
Input2 = 20

It will create total 50 rows and the order is
0
20
40
60
Etc.....

Do you need the codes as below?
......
for (int i = input1 / input2; i >=0; i--) {
......
t1v.setText("" + i * input2);
......

Download size < 0.07 MB. But also Accurate, Ad-Free & Full-Free.
The minimalist app available on Google Play https://goo.gl/ws42fN
Your 5-star is appreciated. Blog : https://okblackcafe.blogspot.com

Helpful?
Reply
  • Forum posts: 1,387

Mar 21, 2021, 3:40:23 AM via Website

What are the variables of input1 and input2? Is this an Android Studio project? Is it compileable?

Check the official developer website for samples & guides.
https://developer.android.com/

Download size < 0.07 MB. But also Accurate, Ad-Free & Full-Free.
The minimalist app available on Google Play https://goo.gl/ws42fN
Your 5-star is appreciated. Blog : https://okblackcafe.blogspot.com

Helpful?
Reply
  • Forum posts: 10

Mar 22, 2021, 10:08:43 AM via Website

Yes this is android studio project.

Both input 1 and input 2 are integers.
Example:
Input1 = 1000
Input2 = 20

It will create total 50 rows and the order is
0
20
40
60
Etc.....

— modified on Mar 22, 2021, 10:48:17 AM

Helpful?
Reply
Best answer
  • Forum posts: 1,387

Mar 23, 2021, 2:05:08 AM via Website

Senthil Kumar.P

Yes this is android studio project.

Both input 1 and input 2 are integers.
Example:
Input1 = 1000
Input2 = 20

It will create total 50 rows and the order is
0
20
40
60
Etc.....

Do you need the codes as below?
......
for (int i = input1 / input2; i >=0; i--) {
......
t1v.setText("" + i * input2);
......

Download size < 0.07 MB. But also Accurate, Ad-Free & Full-Free.
The minimalist app available on Google Play https://goo.gl/ws42fN
Your 5-star is appreciated. Blog : https://okblackcafe.blogspot.com

Helpful?
Reply
  • Forum posts: 10

Mar 23, 2021, 3:53:13 AM via Website

Dear Mr.James,

Thanks for your reply. It really worked for me. Your answer is really helped for me.

Thanks once again

Helpful?
Reply
  • Forum posts: 1,387

Mar 23, 2021, 4:12:59 AM via Website

Senthil Kumar.P

Dear Mr.James,

Thanks for your reply. It really worked for me. Your answer is really helped for me.

Thanks once again

You're welcome. That is just something basic about 'for loop control' in C or Java. Btw, would you like to help me support my free app? Thanks.(laughing)

Download size < 0.07 MB. But also Accurate, Ad-Free & Full-Free.
The minimalist app available on Google Play https://goo.gl/ws42fN
Your 5-star is appreciated. Blog : https://okblackcafe.blogspot.com

Helpful?
Reply