[General Questions and Answers] elsenthil:
Deat Team,

I want to save the values entered on a dynamically created table row edit text.

package com.example.schwingstetterindiapvtlt;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.preference.PreferenceManager;

import com.google.firebase.auth.FirebaseAuth;

public class AggreAscendingorder extends AppCompatActivity {

private TableLayout table;
private TableRow tr;
private DrawerLayout drawerLayout;
private Object Drawable;
public static final String EDIT = "EDIT";
public static final String TEXT = "TEXT";
private int input1;
private int input2;
private int x, s2,q, q1;
private Number Num;
String s1, s_time;
EditText ed1;

@SuppressLint("ResourceType")
public void init() {
TableLayout stk = (TableLayout) findViewById(R.id.table_main);
TableRow tbrow0 = new TableRow(this);
TextView tv0 = new TextView(this);
tv0.setText("Actual Values ");
tv0.setWidth(330);
tv0.setGravity(Gravity.CENTER);
tv0.setTextColor(Color.WHITE);
tv0.setTextSize(12);
tv0.setBackgroundResource(R.drawable.border4);
tbrow0.addView(tv0);
TextView tv1 = new TextView(this);
tv1.setText("Meter Values ");
tv1.setWidth(330);
tv1.setGravity(Gravity.CENTER);
tv1.setTextColor(Color.WHITE);
tv1.setTextSize(12);
tv1.setBackgroundResource(R.drawable.border4);
tbrow0.addView(tv1);
TextView tv2 = new TextView(this);
tv2.setText("Error ");
tv2.setWidth(315);
tv2.setGravity(Gravity.CENTER);
tv2.setTextColor(Color.WHITE);
tv2.setTextSize(12);
tv2.setBackgroundResource(R.drawable.border4);
tbrow0.addView(tv2);

Intent z = getIntent();
input1 = z.getIntExtra(EDIT, 1);
input2 = z.getIntExtra(TEXT, 1);

if (input2 == 0) {
x = 400;
} else {
x = input1 / input2;
}

// For error display as per the plant model selected
SharedPreferences Prefs = PreferenceManager.getDefaultSharedPreferences(AggreAscendingorder.this);
String st5 = Prefs.getString("st5", "");
if (st5.equals("CP18") || st5.equals("CP18TM") || st5.equals("CP21") || st5.equals("M21Z") || st5.equals("M25Z") ){
q = 2;
q1 = -2;
}else if (st5.equals("CP30") || st5.equals("CP45") || st5.equals("M30Z") || st5.equals("CP30ILS") || st5.equals("CP30P") ){
q = 3;
q1 = -3;
}else if (st5.equals("M1") || st5.equals("M1ILS") || st5.equals("M1C") || st5.equals("M1CR") || st5.equals("M1T") ||
st5.equals("M1TR") || st5.equals("M1P") || st5.equals("H1") || st5.equals("H1J") || st5.equals("H1JR")
|| st5.equals("HN1")){
q = 6;
q1 = -6;
}else if (st5.equals("M1.25") || st5.equals("H1.25") || st5.equals("H1.25J") || st5.equals("M1.25ILS") ){
q = 8;
q1 = -8;
}else if (st5.equals("M2") || st5.equals("H2") || st5.equals("M2.25") || st5.equals("M2.5") || st5.equals("H2.25") ||
st5.equals("M3") || st5.equals("H3N") || st5.equals("H3J") || st5.equals("H4N") || st5.equals("H6N")){
q = 16;
q1 = -16;
}

stk.addView(tbrow0);
for (int i = 0; i < x + 1; i++) {
TableRow tbrow = new TableRow(this);
final EditText t1v = new EditText(this);
t1v.setId(1);
if (input2 == 0) {
t1v.setHint("");
} else {
t1v.setText("" + i * input2);
}

t1v.setTextColor(Color.BLACK);
t1v.setGravity(Gravity.CENTER);
t1v.setTextSize(12);
t1v.setInputType(InputType.TYPE_CLASS_NUMBER);
t1v.setBackgroundResource(R.drawable.border);
tbrow.addView(t1v);

final EditText t2v = new EditText(this);
t2v.setHint("");
t2v.setTextColor(Color.BLACK);
t2v.setGravity(Gravity.CENTER);
t2v.setTextSize(12);
t2v.setInputType(InputType.TYPE_CLASS_NUMBER);
t2v.setBackgroundResource(R.drawable.border);
tbrow.addView(t2v);

TextView t3v = new TextView(this);
t3v.setHint("");
t3v.setTextColor(Color.BLACK);
t3v.setGravity(Gravity.CENTER);
t3v.setTextSize(12);
t3v.setBackgroundResource(R.drawable.border);
tbrow.addView(t3v);
stk.addView(tbrow);

//SharedPreferences Prefs = PreferenceManager.getDefaultSharedPreferences(this);
//if (t2v != null) {
// ...
// String s_time = String.valueOf(t2v.getText().toString());
//String save = Prefs.getString("s_time","");
// t2v.setText(String.valueOf(save));

TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

if (!t2v.getText().toString().equals("")) {
int temp1 = Integer.parseInt(t2v.getText().toString());
int temp2 = Integer.parseInt(t1v.getText().toString());
t3v.setText(String.valueOf(temp1 - temp2));
}

if (Integer.valueOf(t3v.getText().toString()) > q || Integer.valueOf(t3v.getText().toString()) < q1 ) {
t3v.setError("Error");
t3v.setTextColor(Color.RED);
}else {
t3v.setError(null);
t3v.setTextColor(Color.BLACK);
}

}

@Override
public void afterTextChanged(Editable s) {
if (t2v.getText().toString().equals("")) {
t3v.setText("");
t3v.setError(null);
t3v.setTextColor(Color.BLACK);
}

}
};
t2v.addTextChangedListener(textWatcher);

}
}
public void newSavedData(){

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getSupportActionBar().hide();
setContentView(R.layout.activity_aggre_ascendingorder);

drawerLayout = findViewById(R.id.drawer_layout);
init();

}
public void ClickMenu(View view) {

NewActivity.openDrawer(drawerLayout);
}
public void ClickLogo(View view)
{
NewActivity.closeDrawer(drawerLayout);
}
public void ClickHome(View view){

NewActivity.redirectActivity(this,NewActivity.class);
}

public void ClickAboutUs(View view){
redirectActivity(this,AboutUs.class);

}
public void ClickExit(View view){

NewActivity.Exit(this);
}

public void ClickLogout(View view) {
LogOut(this);

}

public void LogOut(Activity activity) {

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
builder.setTitle("Logout");
builder.setMessage("Are you sure want to Logout ?");

builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FirebaseAuth.getInstance().signOut();
Intent i2 = new Intent(AggreAscendingorder.this, Login_Activity.class);
i2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i2);

}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();

}
});
builder.show();
}
public static void redirectActivity(Activity activity,Class aclass){
Intent intent = new Intent(activity,aclass);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
}

@Override
protected void onPause () {
super.onPause();
NewActivity.closeDrawer(drawerLayout);
}

@Override
public void onBackPressed() {
Intent i2 = new Intent(AggreAscendingorder.this, Reading.class);
i2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i2);
}

}

Using my above code, when I am editing any values, it saves the last edited value on all the rows.

My screen looks like this View attachment 5309935

Can anyone correct where I am doing the mistake?