Android 如何使用另一个布局id?
在我的应用程序中,我使用了一个警报框。。在这个警告框中,我给出了另一个要显示的布局。。使用Android 如何使用另一个布局id?,android,Android,在我的应用程序中,我使用了一个警报框。。在这个警告框中,我给出了另一个要显示的布局。。使用setView()方法。。我有个问题。如何在我的活动中使用布局元素id LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.volume, null);
setView()
方法。。我有个问题。如何在我的活动中使用布局元素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();
大概是这样的:
在您的活动中:
....
View layout = inflater.inflate(R.layout.volume, null);
.....
View some = layout.findViewById(YOUR_VIEW_ID);
.....
大概是这样的:
在您的活动中:
....
View layout = inflater.inflate(R.layout.volume, null);
.....
View some = layout.findViewById(YOUR_VIEW_ID);
.....
您可以通过
builder.findViewById(R.id.restart)获取对视图的引用代码>您可以通过builder.findViewById(R.id.restart)获取查看的参考代码>如果要在自定义布局中引用视图,请执行以下操作:
EditText editText = (EditText) layout.findViewById(R.id.your_editText);
Button editText = (Button) layout.findViewById(R.id.your_button);
.
.
.
//and so one with other views
如果要在自定义布局中引用视图,请执行以下操作:
EditText editText = (EditText) layout.findViewById(R.id.your_editText);
Button editText = (Button) layout.findViewById(R.id.your_button);
.
.
.
//and so one with other views
此代码显示如何显示自定义警报并从该自定义布局获取视图:
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();
此代码显示如何显示自定义警报并从该自定义布局获取视图:
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();
Hai,在我的应用程序中使用音量控制seekbar。点击一次按钮就会显示出来。所以我使用警报框。该警报框有一个卷布局。我的问题是我没有使用seekbar id。那么我想您应该在xml布局中为您的seekbar分配一个id,以便稍后在codeHai中引用它,在我的应用程序中使用卷控制seekbar。点击一次按钮就会显示出来。所以我使用了警报框。警报框只有一个卷布局。我的问题是我没有使用seekbar id。那么我想您应该在xml布局中为seekbar分配一个id,以便稍后在代码中引用它