editText = (EditText) this.findViewById(R.string.phone);
楼主您好,首先你的这句代码就有问题,你之前已近new了一个editText出来,为什么还有findViewById呢,再说了,findViewById也不是R.String吧,那也应该是R.id吧,首先您的思路就没有整理好
EditText editText = new EditText(this);
editText = (EditText) this.findViewById(R.idphone); 没有见过这样创建控件的。。
这样就好了、 EditText editText = (EditText) this.findViewById(R.id.phone);
一下是布局中没有声明EditText,才这样创建的 EditText editText = new EditText(this);显然你都有id了 肯定在布局文件声明过了。。。
需要为Dialog设置类似如下的监听器:
.setPositiveButton("确定", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1)
{
String number = editText.getText().toString();
Toast.makeText(SmartGuyActivity.this,number,Toast.LENGTH_LONG ).show();
}
})
number = editText.getText().toString();
这一句只是获取edittext中的数据在转换为字符串,你并没有在把number(String)转换为数据型的。所以就会报number出错!
这样有什么问题?出什么错误了?