i added Edit Text dynamically but not get values ,get values for last Edit Text . please help me...
Here is the answer :
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < editTextList.size(); i++) {
System.out.println("Content"+editTextList.get(i).getText().toString());
}
}
});
public class EnterText extends Activity {
Button btnMyLine,btnSave;
LinearLayout LLEnterText;
int _intMyLineCount;
private List<EditText> editTextList = new ArrayList<EditText>();
private List<TextView> textviewList=new ArrayList<TextView>();
private List<LinearLayout> linearlayoutList=new ArrayList<LinearLayout>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.entertext);
LLEnterText=(LinearLayout) findViewById(R.id.LlTitle);
//LLEnterText.setOrientation(LinearLayout.VERTICAL);
btnMyLine=(Button) findViewById(R.id.btnMyLines);
btnSave=(Button) findViewById(R.id.btnSave);
btnMyLine.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LLEnterText.addView(linearlayout(_intMyLineCount));
_intMyLineCount++;
}
});
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (ETTitleEnterText.getText().length() == 0)
{
Toast.makeText(EnterText.this, "Please Enter Full Details", Toast.LENGTH_LONG).show();
}else{
for (EditText editText : editTextList) {
StartTabHost.VARClass._ArrLinesDetails.add(editText.getText().toString());
}
for(TextView textview:textviewList){
StartTabHost.VARClass._ArrLinesTitle.add(textview.getText().toString());
}
for(int i=0;i<StartTabHost.VARClass._ArrLinesTitle.size();i++)
{
Log.d("LinesTitle",StartTabHost.VARClass._ArrLinesTitle.get(i));
Log.d("LinesDetails",StartTabHost.VARClass._ArrLinesDetails.get(i));
}
}
}
});
}
private EditText editText(int _intID) {
EditText editText = new EditText(this);
editText.setId(_intID);
editText.setHint("My lines");
editText.setWidth(180);
editText.setBackgroundColor(Color.WHITE);
editTextList.add(editText);
return editText;
}
private TextView textView(int _intID)
{
TextView txtviewAll=new TextView(this);
txtviewAll.setId(_intID);
txtviewAll.setText("My lines:");
txtviewAll.setTextColor(Color.RED);
txtviewAll.setTypeface(Typeface.DEFAULT_BOLD);
textviewList.add(txtviewAll);
return txtviewAll;
}
private LinearLayout linearlayout(int _intID)
{
LinearLayout LLMain=new LinearLayout(this);
LLMain.setId(_intID);
LLMain.addView(textView(_intID));
LLMain.addView(editText(_intID));
LLMain.setOrientation(LinearLayout.HORIZONTAL);
linearlayoutList.add(LLMain);
return LLMain;
}
}