[英]How to remove a layout from an AlertDialog?
我要刪除具有一個顯示警報對話框的按鈕的布局,它具有一個要刪除布局的按鈕。 此布局位於稱為父布局的TableLayout上。 現在,我可以刪除表格布局中的所有布局,但是我只想要一個。
public OnClickListener editButtonListener = new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// get all necessary GUI components
AlertDialog.Builder builder = new AlertDialog.Builder(MenuCne.this);
builder.setPositiveButton("Remove", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
parentLayout.removeAllViews();
}
});
使用removeView()( http://developer.android.com/reference/android/view/ViewGroup.html#removeView (android.view.View ) )方法中的任何一種,而不要使用removeAllViews()
。 如果您有要刪除的View
的id
,只需使用其id
對其充氣並調用
parentLayout.removeView(aView); // where aView is the View you inflated to remove
還有removeViewAt(Index i)
來刪除該位置的layout
中的視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.