我正在尝试在对话框中添加edittext,但是当我尝试在对话框中添加edittext时,它会显示在每个新编辑文本的上方。什么我得到这个.... 在对话框中添加动态编辑文本
但我想这样.....
当我点击添加图片按钮,然后新的TextView应该在屏幕中添加。我写了如下代码:
final RelativeLayout.LayoutParams params= new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
Log.w("Addfriendsactivity", "friendsCount--first time-> "+friendsCount);
friendsCount++;
EditText textview = new EditText(context);
Log.w("Addfriendsactivity", "friendsCount---> "+friendsCount);
textview.setId(friendsCount);
params.addRule(RelativeLayout.BELOW, friendsCount--);
friendsCount += 1;
Log.w("Addfriendsactivity", "friendsCount--third time-> "+friendsCount);
textview.setLayoutParams(params);
textview.setVisibility(View.VISIBLE);
Log.w("Addfriendsactivity", "params---> "+params);
Log.w("Addfriendsactivity", "textview---> "+textview);
Log.w("Addfriendsactivity", "relativelayout--> "+textview);
dialog.addContentView(textview ,params);
textview.setText(String.valueOf(friendsCount));
Log.d("addFriendsActivity", "ashish comes here ");
}
catch (Exception e) {
e.printStackTrace();
}
});
}
任何人都可以帮助我解释为什么发生这种情况如何从这个问题出来?
在此先感谢..
编辑
我的XML布局如下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".AddFriendsCustomActivity" >
<EditText
android:id="@+id/writename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="24dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/submit_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/writename"
android:layout_below="@+id/add"
android:layout_marginRight="46dp"
android:text="Submit" />
<ImageView
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/writename"
android:layout_marginLeft="22dp"
android:layout_toRightOf="@+id/writename"
android:contentDescription="Add Friend"
android:src="@drawable/add" />
</RelativeLayout>
与垂直方向的,而不是RelativeLayou实现的LinearLayout。试试这个 –
@MD你能告诉哪里和什么链接? – Ashishsingh