专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Android

关于自定义对话框

发布时间:2010-05-30 10:53:20 文章来源:www.iduyao.cn 采编人员:星星草
求助关于自定义对话框
要添加进对话框的视图
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:id="@+id/textview" android:layout_below="@+id/editText_savename"></TextView>
</RelativeLayout>

对话框函数
void test(){
LayoutInflater factory = LayoutInflater.from(this);
final View newdialog= factory.inflate(R.layout.newdialog,null);
TextView textview = (TextView)findViewById(R.id.textview );
Log.d("debug","test");//能走到这一步
textview.setText("test");这里出错,nullpointerException
new AlertDialog.Builder(this)
.setView(view_savaname)
.show();
}
按一下按钮,调用这个函数,出现错误说明找不到控件么,怎么样才能找到控件啊

------解决方案--------------------
把你这一句:TextView textview = (TextView)findViewById(R.id.textview );
改成 TextView textview = (TextView)newdialog.findViewById(R.id.textview );



就可以了。
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: