android r.id 自定义,自定义AlertDialog – android.R.id.custom的问题

我确定我错过了这里的重点,所以我希望有人可以解释.

我想在用户触摸ImageView时创建一个弹出窗口.我看了一下AlertDialog,文档说……

If you want to display a more complex view,look up the FrameLayout called “custom” and add your view to it:

……使用以下代码……

FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);

fl.addView(myView,new LayoutParams(MATCH_PARENT,WRAP_CONTENT));

所以作为测试我在onCLick()方法中尝试了以下内容……

TextView tv = new TextView(this);

tv.setText("Hello World");

FrameLayout customFrameLayout = (FrameLayout) findViewById(android.R.id.custom);

customFrameLayout.addView(tv,new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));

上面我调用addView()的最后一行抛出一个NullPointerException,这让我觉得android.R.id.custom存在问题.

所以问题是,上面有什么问题,还有更好的方法来创建自定义弹出窗口(可能通过使用Dialog类或扩展它)?

注意:我只是在这个例子中使用TextView作为测试,我想为我的实际弹出窗口添加更复杂的东西.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值