Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

Android: How to copy values from one column to a new column in Android table layout before updating the table

I am very new to Android app development. I want to maintain a copy of a col to a new col before updating the table. What I'm currently doing is before updating the table in the table layout is removeAllViews(). But before removing I want to save the copy of the last updated values of a particular column. So i want to add another column (say: lastUpdatedFSIDs) which should contain the data of FSID column of previous update.

My current implementation is like below:

public void init(long [] array) {

    TableLayout stk = (TableLayout) findViewById(R.id.table_main);
    stk.removeAllViews();
    String[] s=new  String[array.length];
    for(int k=0;k<array.length;k++)
    {
        s[k]= Long.toHexString(array[k]);
        Log.i(TAG,"Strings in array:"+ s[k]);
    }

    TableRow tbrow0 = new TableRow(this);
    TextView tv0 = new TextView(this);
    tv0.setText(" Sl.No ");
    tv0.setTextColor(Color.WHITE);
    tv0.setTextSize(20);
    tv0.setWidth(100);
    tbrow0.addView(tv0);
    TextView tv1 = new TextView(this);
    tv1.setText(" FSID ");
    tv1.setTextColor(Color.WHITE);
    tv1.setTextSize(20);
    tv1.setWidth(100);
    tbrow0.addView(tv1);
    TextView tv2 = new TextView(this);
    tv2.setText(" Status ");
    tv2.setTextColor(Color.WHITE);
    tv2.setTextSize(20);
    tv2.setWidth(100);
    tbrow0.addView(tv2);
    TextView tv3 = new TextView(this);
    tv3.setText(" Functionality ");
    tv3.setTextColor(Color.WHITE);
    tv3.setTextSize(20);
    tv3.setWidth(200);
    tbrow0.addView(tv3);
    stk.addView(tbrow0);
    for (int i = 0; i < s.length; i++) {
        TableRow tbrow = new TableRow(this);
        TextView t1v = new TextView(this);
        t1v.setText("" + i);
        t1v.setTextColor(Color.WHITE);
        t1v.setGravity(Gravity.CENTER);
        t1v.setTextSize(15);
        tbrow.addView(t1v);
        stk.addView(tbrow);
        TextView t2v = new TextView(this);
        t2v.setText(s[i]);
        t2v.setTextColor(Color.WHITE);
        t2v.setGravity(Gravity.CENTER);
        t2v.setTextSize(15);
        tbrow.addView(t2v);

//... } }

Thanks in advance.

question from:https://stackoverflow.com/questions/66061985/android-how-to-copy-values-from-one-column-to-a-new-column-in-android-table-lay

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...