android 获取动态添加的控件,android动态加载控件(LinearLayout)并获取动态添加的EditText里的值...
View validateView = inflater.inflate(R.layout.dialog_validate, null);final LinearLayout layout_validate = (LinearLayout) validateView.findViewById(R.id.layout_validate);layout_validate.removeAllViews(
View validateView = inflater.inflate(
R.layout.dialog_validate, null);
final LinearLayout layout_validate = (LinearLayout) validateView.findViewById(R.id.layout_validate);
layout_validate.removeAllViews();
final List> list = new ArrayList>();
for(int i=0;i
Map map = new HashMap();
View validateItem = inflater.inflate(
R.layout.item_validate_enter, null);
validateItem.setTag(i);
layout_validate.addView(validateItem);
TextView tv_validateName = (TextView) validateItem.findViewById(R.id.tv_validateName);
map.put("name", tv_validateName);
EditText et_validate = (EditText) validateItem.findViewById(R.id.et_validate);
map.put("value", et_validate);
tv_validateName.setText(valiStr[i]);
list.add(map);
}
AlertDialog dialog = new AlertDialog.Builder(this).setTitle("填写入群信息:")
.setView(validateView)
.setPositiveButton("确定", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
StringBuffer stringBuffer = new StringBuffer();
for(int i=0;i
String name = ((TextView)list.get(i).get("name")).getText().toString();
String value = ((EditText)list.get(i).get("value")).getText().toString();
stringBuffer.append(name+value+",");
}
verifyparams = stringBuffer.substring(0, stringBuffer.length()-1);
sendJoinRequest();
dialog.dismiss();
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
}).create();
dialog.show();
dialog_validate.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/layout_validate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="2dp"
android:paddingBottom="5dp"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="1dp"
android:orientation="vertical" />
item_validate_enter.xml
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal" >
android:id="@+id/tv_validateName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="right|center_vertical"
android:layout_marginRight="5dp"
android:text="姓名:"
android:textColor="@color/white"
android:textSize="16sp"
android:layout_weight="2"/>
android:id="@+id/et_validate"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:background="@null"
/>
ok解决更多推荐
所有评论(0)