zoukankan      html  css  js  c++  java
  • 安卓自己定义对话框及The specified child already has a child问题

    问题:在android开发过程中,有时会在不同情况下遇到同种问题:The specified child already has a parent.You must call removeView() on the child's parent first.日志中例如以下图所看到的:


    分析:意思是这个特定的child已经有一个parent了,假设你要继续使用它,就必须先调用removeView()方法移除它原来的的parent,才干继续你的内容。

    举例:在主activity中点击按键弹出自己定义View的对话框

    首先:

    setContentView(R.layout.main); 

    etContentView(R.layout.main
    其次

    其次:对button进行click监听,click函数里调用对话框函数

    1.对话框的处理:新建defView,里面有一个edittext(其它控件的也一样)

      <EditText 
            android:id="@+id/filename"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    2.由于对话框中要调用的控件不在布局文件main.xml中,所以我们必须先调用布局填充类的相关函数找到该布局

    LinearLayout def = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_save_file, null);

    3.然后在该布局中找到对应的控件:

    edtTxtFileName = (EditText) saveForm.findViewById(R.id.filename);

    4.click函数中对话框的建立

    AlertDialog.Builder builder = new AlertDialog.Builder(this)
    				.setTitle("保存sdcard/sign/").setIcon(R.drawable.save_file)
    				.setView(def);//这里给对话框增加了自己定义的内容
    </pre><pre name="code" class="java">最后:在对话框本身的按键确定或者取消click响应中增加:
    ((ViewGroup) saveForm.getParent()).removeView(def);
    

  • 相关阅读:
    记录log中的16进制和ASCII码字符输出
    有效的沟通技巧
    时间的真谛
    目标设定与时间管理
    第四代时间管理
    什么是高效沟通
    error LNK1104: cannot open file 错误解决方案
    js压缩工具1.0界面绘制
    时间管理的定义与目的
    JArgs命令行选项解析>Java套件
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5180987.html
Copyright © 2011-2022 走看看