'Please find this attachment I have created an XML file with only one edit text. and in java class i'm dynamically inflating the XML file to create multiple edit text fields. now the problem is resource id are same for all the edit text fields. so is there any way to give different resource ids. please help me.
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.LinearLayout;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
EditText[] sample;
Boolean Valid;
ArrayList<String> obj_array = new ArrayList<>();
LinearLayout root_layout;
LayoutInflater inflater;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
root_layout = (LinearLayout) findViewById(R.id.root);
init();
}
private void init() {
obj_array.add("abc");
obj_array.add("def");
obj_array.add("ghi");
obj_array.add("jkl");
assignToValue();
}
private void assignToValue() {
sample = new EditText[obj_array.size()];
for (int i = 0; i < obj_array.size(); i++) {
// here i'm dynamically creating edit text .
View v= inflater.inflate(R.layout.edittext,null);
sample[i] = (EditText) v.findViewById(R.id.edit);
sample[i].setText(obj_array.get(i));
root_layout.addView(sample[i]);
}
}
}'