android自定义的对话框怎么调用
android中用自定义的对话框,分装成一个类后,怎么调用?(比如我在一个页面按下按钮后弹出我自定义的对话框,是自定义不是弹出系统的,系统的我可以直接建立,怎么调用被封装...
android中用自定义的对话框,分装成一个类后,怎么调用?(比如我在一个页面按下按钮后弹出我自定义的对话框,是自定义不是弹出系统的,系统的我可以直接建立,怎么调用被封装好的类啊
MyDialogTo dialog = new MyDialogTo(content, R.style.mydialog1);//申明一个dialog对象
// dialog.setContentView(R.layout.mydialogfirst);
dialog.show();
这两句不行啊)
怎么对自定义的对话框里的按钮等等在添加事件?在哪儿的java里添加呢 展开
MyDialogTo dialog = new MyDialogTo(content, R.style.mydialog1);//申明一个dialog对象
// dialog.setContentView(R.layout.mydialogfirst);
dialog.show();
这两句不行啊)
怎么对自定义的对话框里的按钮等等在添加事件?在哪儿的java里添加呢 展开
2个回答
展开全部
Android自定义对话框的思路就是编写对话框的布局文件xml,然后在对话框中显示不同的控件。以下以显示文本控件为例(ImageView等都可以显示)。
1.布局文件connect_dlg.xml(比如http://www.tiecou.com/)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#ffffffff"
android:orientation="vertical"
android:id="@+id/llToast" >
<TextView
android:layout_height="wrap_content"
android:layout_margin="1dip"
android:textColor="#ffffffff"
android:layout_width="fill_parent"
android:gravity="center"
android:textSize="16sp"
android:background="#FF129de2"
android:id="@+id/tvTitleToast" />
<LinearLayout
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/llToastContent"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:layout_marginBottom="1dip"
android:layout_width="wrap_content"
android:padding="15dip"
android:background="#FFFFFFFF" >
<TextView
android:layout_height="wrap_content"
android:paddingRight="10dip"
android:paddingLeft="10dip"
android:layout_width="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:textColor="#FFff6699"
android:id="@+id/tvTextToast" />
</LinearLayout>
<LinearLayout
android:id="@+id/MyLayout_ad2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40sp">
<com.tencent.exmobwin.banner.TAdView
android:id="@+id/adview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|right" >
</com.tencent.exmobwin.banner.TAdView>
</LinearLayout>
</LinearLayout>
2.编写显示对话框函数。ShowConnectDialog(String textString)
private void ShowConnectDialog(String textString) {
LinearLayout loginLayout1 = (LinearLayout) getLayoutInflater().inflate(
R.layout.connect_dlg, null);
// adView.
TextView title = (TextView) loginLayout1
.findViewById(R.id.tvTitleToast);
title.setText("系统提示");
TextView text1 = (TextView) loginLayout1.findViewById(R.id.tvTextToast);
text1.setText(textString);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(loginLayout1);
builder.setPositiveButton("下载MobCtrl服务器?", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//处理确定按钮
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 处理取消按钮
finish();
}
});
builder.create().show();
}
3.显示对话框。在需要显示的地方调用即可。
ShowConnectDialog("连接超时,请检查服务器是否开启及IP地址是否输入正确。确保电脑和手机连接在同一个网络内。");
1.布局文件connect_dlg.xml(比如http://www.tiecou.com/)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#ffffffff"
android:orientation="vertical"
android:id="@+id/llToast" >
<TextView
android:layout_height="wrap_content"
android:layout_margin="1dip"
android:textColor="#ffffffff"
android:layout_width="fill_parent"
android:gravity="center"
android:textSize="16sp"
android:background="#FF129de2"
android:id="@+id/tvTitleToast" />
<LinearLayout
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/llToastContent"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:layout_marginBottom="1dip"
android:layout_width="wrap_content"
android:padding="15dip"
android:background="#FFFFFFFF" >
<TextView
android:layout_height="wrap_content"
android:paddingRight="10dip"
android:paddingLeft="10dip"
android:layout_width="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:textColor="#FFff6699"
android:id="@+id/tvTextToast" />
</LinearLayout>
<LinearLayout
android:id="@+id/MyLayout_ad2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40sp">
<com.tencent.exmobwin.banner.TAdView
android:id="@+id/adview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|right" >
</com.tencent.exmobwin.banner.TAdView>
</LinearLayout>
</LinearLayout>
2.编写显示对话框函数。ShowConnectDialog(String textString)
private void ShowConnectDialog(String textString) {
LinearLayout loginLayout1 = (LinearLayout) getLayoutInflater().inflate(
R.layout.connect_dlg, null);
// adView.
TextView title = (TextView) loginLayout1
.findViewById(R.id.tvTitleToast);
title.setText("系统提示");
TextView text1 = (TextView) loginLayout1.findViewById(R.id.tvTextToast);
text1.setText(textString);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(loginLayout1);
builder.setPositiveButton("下载MobCtrl服务器?", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//处理确定按钮
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 处理取消按钮
finish();
}
});
builder.create().show();
}
3.显示对话框。在需要显示的地方调用即可。
ShowConnectDialog("连接超时,请检查服务器是否开启及IP地址是否输入正确。确保电脑和手机连接在同一个网络内。");
展开全部
//定义一个电话对话框
public void CallDialog(final Context ctx,final String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg);
//builder.setTitle(Strings.getString(R.string.call_us_Button));
builder.setNegativeButton(getString(R.string.cancel),new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
HashMap<String, String> analytics = new HashMap<String, String>();
analytics.put("title", fb.getName());
MobclickAgent.onEvent(context, "storetel",analytics);
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + msg));
startActivity(intent);
if(!wb.isCollect(fb.getId(),WbcDb.MYORDERNAME)){
if(map1 != null){
fb.setImagethumb_too(new BitmapDrawable(map1));
}
if(wb.insertCollectOne(fb,WbcDb.MYORDERNAME)){
Toast.makeText(context, "已经添加到我的订单", 1).show();
}else{
Toast.makeText(context, "添加到我的订单失败", 1).show();
}
// startActivity(new Intent(context,CollectActivity.class));
}else{
Util.System("我的订单里边有了");
}
} catch (Exception e) {
// LogUtil.d("PostActivity", e.toString());
e.printStackTrace();
}
}
});
builder.create().show();
}
给你一个方法,你稍微修改一下,以后要用对话框就用这个末班
public void CallDialog(final Context ctx,final String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg);
//builder.setTitle(Strings.getString(R.string.call_us_Button));
builder.setNegativeButton(getString(R.string.cancel),new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
HashMap<String, String> analytics = new HashMap<String, String>();
analytics.put("title", fb.getName());
MobclickAgent.onEvent(context, "storetel",analytics);
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + msg));
startActivity(intent);
if(!wb.isCollect(fb.getId(),WbcDb.MYORDERNAME)){
if(map1 != null){
fb.setImagethumb_too(new BitmapDrawable(map1));
}
if(wb.insertCollectOne(fb,WbcDb.MYORDERNAME)){
Toast.makeText(context, "已经添加到我的订单", 1).show();
}else{
Toast.makeText(context, "添加到我的订单失败", 1).show();
}
// startActivity(new Intent(context,CollectActivity.class));
}else{
Util.System("我的订单里边有了");
}
} catch (Exception e) {
// LogUtil.d("PostActivity", e.toString());
e.printStackTrace();
}
}
});
builder.create().show();
}
给你一个方法,你稍微修改一下,以后要用对话框就用这个末班
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询