我正在嘗試在對話框中添加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