添加的EditText动态和检索的Android值 [英] Add edittext dynamically and retrieve values in android
本文介绍了添加的EditText动态和检索的Android值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我添加编辑文本动态,但没有得到值,获得最后的编辑文本值。 请帮我...
解决方案
公共类EnterText延伸活动{
按钮btnMyLine,btnSave;
的LinearLayout LLEnterText;
INT _intMyLineCount;
私人列表<的EditText> editTextList =新的ArrayList<的EditText>();
私人列表< TextView的> textviewList =新的ArrayList< TextView的>();
私人列表<的LinearLayout> linearlayoutList =新的ArrayList<的LinearLayout>();
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.entertext);
LLEnterText =(的LinearLayout)findViewById(R.id.LlTitle);
//LLEnterText.setOrientation(LinearLayout.VERTICAL);
btnMyLine =(按钮)findViewById(R.id.btnMyLines);
btnSave =(按钮)findViewById(R.id.btnSave);
btnMyLine.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
LLEnterText.addView(的LinearLayout(_intMyLineCount));
_intMyLineCount ++;
}
});
btnSave.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
如果(ETTitleEnterText.getText()长度()== 0)
{
Toast.makeText(EnterText.this,请输入全部详细资料,Toast.LENGTH_LONG).show();
}其他{
对于(的EditText EDITTEXT:editTextList){
StartTabHost.VARClass._ArrLinesDetails.add(editText.getText()的toString());
}
对于(TextView中的TextView:textviewList){
StartTabHost.VARClass._ArrLinesTitle.add(textview.getText()的toString());
}
的for(int i = 0; I< StartTabHost.VARClass._ArrLinesTitle.size();我++)
{
Log.d(LinesTitle,StartTabHost.VARClass._ArrLinesTitle.get(ⅰ));
Log.d(LinesDetails,StartTabHost.VARClass._ArrLinesDetails.get(ⅰ));
}
}
}
});
}
私人的EditText EDITTEXT(INT _intID){
EditText上EDITTEXT =新的EditText(本);
editText.setId(_intID);
editText.setHint(我行);
editText.setWidth(180);
editText.setBackgroundColor(Color.WHITE);
editTextList.add(EDITTEXT);
返回EDITTEXT;
}
私人TextView中的TextView(INT _intID)
{
TextView的txtviewAll =新的TextView(本);
txtviewAll.setId(_intID);
txtviewAll.setText(我的台词:);
txtviewAll.setTextColor(Color.RED);
txtviewAll.setTypeface(Typeface.DEFAULT_BOLD);
textviewList.add(txtviewAll);
返回txtviewAll;
}
私人的LinearLayout的LinearLayout(INT _intID)
{
的LinearLayout LLMain =新的LinearLayout(本);
LLMain.setId(_intID);
LLMain.addView(TextView中(_intID));
LLMain.addView(EDITTEXT(_intID));
LLMain.setOrientation(LinearLayout.HORIZONTAL);
linearlayoutList.add(LLMain);
返回LLMain;
}
}
i added Edit Text dynamically but not get values ,get values for last Edit Text . please help me...
解决方案
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;
}
}
这篇关于添加的EditText动态和检索的Android值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文