我添加加的EditText在我的活動 安卓計數所有的EditText
我不能calulate所有的EditText值
public void listAllAddView(){
int childCount = container.getChildCount();
EditText[] editTexts;
int total = 0;
for(int i=0; i<childCount; i++){
View thisChild = container.getChildAt(i);
EditText childTextView = (EditText) thisChild.findViewById(R.id.textout);
String childTextViewValue = childTextView.getText().toString();
Toast.makeText(MainActivity.this, childTextViewValue, Toast.LENGTH_LONG).show();
}
}
如何在EditText上和值和用戶可以添加更多的EditText價格
代碼添加
buttonAdd.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
EditText textOut = (EditText)addView.findViewById(R.id.textout);
textOut.setText(textIn.getText().toString());
ImageView buttonRemove = (ImageView)addView.findViewById(R.id.remove);
final View.OnClickListener thisListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
((LinearLayout)addView.getParent()).removeView(addView);
listAllAddView();
}
};
buttonRemove.setOnClickListener(thisListener);
container.addView(addView);
listAllAddView();
}
});
謝謝你<3 它的工作原理 –