2012-03-16 91 views
0

在我的應用程序中,我使用了一個警報框..在這個警報框中,我給出了另一個顯示佈局..使用setView()方法..我有一個問題。如何在我的活動中使用佈局元素ID?如何使用其他佈局ID?

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       View layout = inflater.inflate(R.layout.volume, null); 
       builder.setTitle("Volume"); 
       builder.setView(layout); 
       builder.setPositiveButton("OK", null); 
       builder.setNegativeButton("Cancel", null); 
       AlertDialog alert1 = builder.create(); 
       alert1.show(); 
+0

闡述您的問題... – waqaslam 2012-03-16 12:50:34

+0

海,在我的應用程序使用量控制搜索條。這應該出現在一個buuton點擊。所以我使用警報box.that警報框有一個卷佈局..我problam是我沒有使用seekbar id .. – Palaniraja 2012-03-16 14:08:41

+0

然後我想你應該在xml佈局中指定一個ID到你的seekbar以便稍後參考它在代碼 – waqaslam 2012-03-16 14:13:23

回答

1

這段代碼演示瞭如何顯示自定義的警報,並得到從自定義佈局視圖:

AlertDialog mDialog = null; 

    Context mContext = getApplicationContext(); 
    final AlertDialog.Builder my_Dialog = new AlertDialog.Builder(this); 
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); 
    View layout = inflater.inflate(R.layout.my_dialog, (ViewGroup) findViewById(R.id.layout_root)); 

    ImageView imageViewInsideLayout = (ImageView) layout.findViewById(R.id.imageviewLayout); 

    my_Dialog.setView(layout); 
    mDialog = my_Dialog.create(); 
    mDialog.show(); 
+0

謝謝.. problam解決了 – Palaniraja 2012-03-16 14:25:03

2

事情是這樣的:

在你的活動:

.... 
View layout = inflater.inflate(R.layout.volume, null); 
..... 
View some = layout.findViewById(YOUR_VIEW_ID); 
..... 
+0

謝謝你...它工作正常 – Palaniraja 2012-03-16 14:25:47

1

你可以參考由builder.findViewById(R.id.restart);

如果要引用,查看您的自定義佈局內
2

查看,然後執行以下操作:

EditText editText = (EditText) layout.findViewById(R.id.your_editText); 
Button editText = (Button) layout.findViewById(R.id.your_button); 
. 
. 
. 
//and so one with other views 
+0

謝謝..它的工作很好.. – Palaniraja 2012-03-16 14:25:22

相關問題