import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void on(View view){
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("title");
LayoutInflater inflater = getLayoutInflater();
final View v = inflater.inflate(R.layout.diy, null);
dialog.setView(v);
dialog.setPositiveButton("text", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText editText = (EditText) findViewById(R.id.editText1);
String string = editText.getText().toString();
Toast.makeText(MainActivity.this, string, Toast.LENGTH_SHORT).show();
}
});
dialog.show();
}
}
错误提示32行空指针异常,找了好久也没有找到哪里错了。。。