求助关于自定义对话框
要添加进对话框的视图
<?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 );
就可以了。
关于自定义对话框
求助关于自定义对话框要添加进对话框的视图?xml version1.0 encodingutf-8?RelativeLayoutxmlns:
