2012-03-16 50 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

相关问题