当前位置:网站首页>Alertdialog create dialog
Alertdialog create dialog
2022-07-07 17:37:00 【XLMN】
alertDialog Create dialog box
alertDialog The generation dialog box can be divided into the following 4 Regions
1、 Icon area
2、 Title Area
3、 Content area
4、 Button area
public class MainActivity extends Activity {
private ClipboardManager show;
String[] items = new String[]{
“ List item 1”,
“ List item 2”,
“ List item 3”,
“ List item 4”
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alertdialog);
}
public void simple(View source) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
// Set dialog title
.setTitle(" Simple dialog ")
// Set icon
.setIcon(R.drawable.mia3)
.setMessage(" The second line of the dialog box tests the content /n");
// by alterDalog.builder add to “ determine ” Button
setPositiveButton(builder);
// by alterDalog.builer Add cancel button
setNegativeButton(builder).create().show();
}
private AlertDialog.Builder setPositiveButton(AlertDialog.Builder builder) {
// call setpostivitybutton Method to add the OK button
return builder.setPositiveButton(" determine ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
show.setText(" Click 【 determine 】 Button ");
}
});
}
private AlertDialog.Builder setNegativeButton(AlertDialog.Builder builder) {
return builder.setNegativeButton(" Cancel ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
show.setText(" Click 【 Cancel 】 Button ");
}
});
}
public void simpleList(View source) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
// Set dialog title
.setTitle(" Simple list item dialog ")
// Set icon
.setIcon(R.drawable.mia3)
// Set simple list item content
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
show.setText(" You chose 《" + items[which] + "》");
}
});
// by alertdialog.builder add to “ determine ” Button
setPositiveButton(builder);
// by alertdialog.builder add to “ Cancel ” Button
setNegativeButton(builder).create().show();
}
public void singleChoice(View source) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
// Set dialog title
.setTitle(" Radio list item dialog ")
// Set icon
.setIcon(R.drawable.mia3)
// Set radio list items , The second item is selected by default ( The index for 1)
.setSingleChoiceItems(items, 1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
show.setText(" You chose 《" + items[which] + "》");
}
});
// by AlertDialog.builder add to “ determine ” Button
setPositiveButton(builder);
// by AlertDialog.builder add to “ Cancel ” Button
setNegativeButton(builder)
.create().show();
}
public void multiChoice(View source) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
// Set dialog title
.setTitle(" Multi select list item dialog box ")
// Set icon
.setIcon(R.drawable.mia3)
// Set multiple list items , Set check box 2 , Item four
.setMultiChoiceItems(items, new boolean[]{false, true, false, true}, null);
// by alertDialog.Builder add to “ determine ” Button
setPositiveButton(builder);
// by alertDialog.builder add to “ Cancel ” Button
setNegativeButton(builder)
.create().show();
}
public void customList(View source) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
// Set dialog title
.setTitle(" Customize the list dialog ")
// Set icon
.setIcon(R.drawable.mia3)
// Set custom list items
.setAdapter(new ArrayAdapter<String>(this, R.layout.array_item, items), null);
// by alertdialog.builder add to “ determine ” Button
setPositiveButton(builder);
// by alertdialog.builder add to “ Cancel ” Button
setNegativeButton(builder).create().show();
}
public void customView(View source) {
// Load interface layout file
TableLayout tl = (TableLayout) getLayoutInflater().inflate(R.layout.login, null);
new AlertDialog.Builder(this)
// Settings dialog icon
.setIcon(R.drawable.mia3)
// Set dialog title
.setTitle(“ Custom dialog ”)
// Set the view object
.setView(tl)
// Set an OK button for the dialog
.setPositiveButton(“ Sign in ”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Login processing can be performed here
}
})
// Set a cancel button for the dialog
.setNegativeButton(“ Cancel ”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Cancel login and do nothing
}
})
// Create and display dialog
.create().show();
}
}
<?xml version="1.0" encoding="utf-8"?><Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="customList"
android:text=" Customize the list dialog "/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="customView"
android:text=" Customize view Dialog box "/>
<?xml version="1.0" encoding="utf-8"?> <TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" user name "
android:textSize="10pt" />
<!-- Enter the user name text box -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint=" Please fill in the login account number "
android:selectAllOnFocus="true" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" password "
android:textSize="10pt" />
<!-- Enter the text box for the password -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint=" Please fill in the password "
android:password="true" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Phone number "
android:textSize="10pt" />
<!-- Enter the text box for the phone number -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint=" Please fill in your password "
android:selectAllOnFocus="true"
android:phoneNumber="true" />
</TableRow>

边栏推荐
- 【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
- A tour of grpc:03 - proto serialization / deserialization
- Problems encountered in Jenkins' release of H5 developed by uniapp
- The mail server is listed in the blacklist. How to unblock it quickly?
- With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
- toast会在程序界面上显示一个简单的提示信息
- alertDialog創建对话框
- DNS series (I): why does the updated DNS record not take effect?
- Audio device strategy audio device output and input selection is based on 7.0 code
- Sator推出Web3遊戲“Satorspace” ,並上線Huobi
猜你喜欢

【分布式理论】(二)分布式存储

datepicket和timepicket,日期、时间选择器的功能和用法

Biped robot controlled by Arduino
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism

Sator推出Web3游戏“Satorspace” ,并上线Huobi

Nerf: the ultimate replacement for deepfake?

serachview的功能和用法

请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取

【可信计算】第十二次课:TPM授权与会话

Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
随机推荐
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
From Devops to mlops: how do it tools evolve to AI tools?
Several best practices for managing VDI
本周小贴士#134:make_unique与私有构造函数
使用 xml资源文件定义菜单
【TPM2.0原理及应用指南】 9、10、11章
Functions and usage of imageswitch
LeetCode刷题day49
A tour of grpc:03 - proto serialization / deserialization
99% of users often make mistakes in power Bi cloud reports
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
Functions and usage of viewswitch
TabHOST 选项卡的功能和用法
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
SlashData开发者工具榜首等你而定!!!
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
【饭谈】如何设计好一款测试平台?
Flash build API service
无法链接远程redis服务器(解决办法百分百)