AlertDialog的片段 [英] AlertDialog in fragments

查看:141
本文介绍了AlertDialog的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些困难,让 AlertDialog 的片段工作。我有六个按键和点击每个按钮时, AlertDialog 框应显示其内容。即使是PRG没有任何错误和TAT片段页面运行与按钮打开,如果我上的按钮DialogBox的是不开放任何人都可以帮我点击?先谢谢了。

下面是我的片段活动code:

  @TargetApi(Build.VERSION_ codeS.HONEYCOMB)
公共类Fragment3扩展DialogFragment实现OnClickListener {    私有静态最终诠释ALERT_DIALOG1 = 1;
  私有静态最终诠释ALERT_DIALOG2 = 2;
  私有静态最终诠释ALERT_DIALOG3 = 3;
  私有静态最终诠释ALERT_DIALOG4 = 4;
  私有静态最终诠释ALERT_DIALOG5 = 5;  @覆盖
  公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
            捆绑savedInstanceState){
      //setContentView(R.layout.activity_fragment2);
    查看查看= inflater.inflate(R.layout.fragment3layout,集装箱,FALSE);      按钮报警1 =(按钮)view.findViewById(R.id.Button1);
      alert1.setOnClickListener(新View.OnClickListener(){
        公共无效的onClick(查看视图){
          的ShowDialog(ALERT_DIALOG1);
      }
  }); 默认:
        对话框= NULL;
    }
    返回对话框;}

下面是我的清单文件

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.pacificstereoapp
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =16/>
            &所述; /意图滤光器>
        < /活性GT;
        <活动
            机器人:名字=com.example.a.Fragment1
            机器人:标签=@字符串/ title_activity_fragment1>
        < /活性GT;    < /用途>< /清单>


解决方案

您正在创建对话框,但没有真正显示它。呼叫 dialog.show()

I have some difficulties getting AlertDialog working in fragments. I have six buttons and when each button is clicked AlertDialog box should display its content. even though the prg is running without any error and tat fragment page is opening with the buttons if i click on a button dialogbox is not opening can anyone help me out? Thanks in advance.

Here is my fragment activity code:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Fragment3 extends  DialogFragment implements OnClickListener  {

    private static final int ALERT_DIALOG1 = 1;
  private static final int ALERT_DIALOG2 = 2;
  private static final int ALERT_DIALOG3 = 3;
  private static final int ALERT_DIALOG4 = 4;
  private static final int ALERT_DIALOG5 = 5;



  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
      //setContentView(R.layout.activity_fragment2);
    View view =  inflater.inflate(R.layout.fragment3layout, container, false);

      Button alert1 = (Button) view.findViewById(R.id.Button1);
      alert1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
          showDialog(ALERT_DIALOG1);
      }
  });



 default:
        dialog = null;
    }
    return dialog;

}

Here is my Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.pacificstereoapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />


            </intent-filter>
        </activity>
        <activity
            android:name="com.example.a.Fragment1"
            android:label="@string/title_activity_fragment1" >
        </activity>

    </application>

</manifest>

解决方案

You are creating dialog, but not really showing it. Call dialog.show().

这篇关于AlertDialog的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆