嗨,我正在研究 ShowDialog,我希望它显示一条带有 2 个局部变量的消息。出于这个原因,它说有一个错误,所以如果有一种方法可以显示这些变量,我将不胜感激。这是我的代码,错误所在的行是这一行:
.setMessage("The NIF is" +user +DNIWord "-")
其余的代码是这个:
protected Dialog onCreateDialog (int id){
switch (id) {
case DIALOG_ERROR_CANDIDATO:
return new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_error)
.setTitle(R.string.error)
.setMessage("The NIF is" +user +DNIWord "-")
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
}
return null;
}
2个变量从这里获得:
int user = Integer.parseInt(dniText.getText().toString());
public static String DNIWord(int user) {
return String.valueOf(user) + NIF_STRING_ASOCIATION.charAt(user % 23);
}
谢谢
编辑:
package com.prueba.inicio;
import com.prueba.R;
import com.prueba.R.drawable;
import com.prueba.R.id;
import com.prueba.R.layout;
import com.prueba.R.string;
import com.prueba.inicio.Autorizacion;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.style.BackgroundColorSpan;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
public class Ident extends Activity {
private static final int DIALOG_ERROR_CANDIDATO= 0;
public static final String NIF_STRING_ASOCIATION = "TRWAGMYFPDXBNJZSQVHLCKE";
public static String DNIWord(int user) {
return String.valueOf(user) + NIF_STRING_ASOCIATION.charAt(user % 23);
}
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.identificacion);
Button bSiguiente = (Button) findViewById(R.id.btn_siguiente);
final EditText dniText = (EditText) findViewById(R.id.dni_candidato);
bSiguiente.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
int user = Integer.parseInt(dniText.getText().toString());
String longitud = dniText.getText().toString();
if(user==8){
Intent i = new Intent(Ident.this,Autorizacion.class);
startActivity(i);
}
else{
showDialog(DIALOG_ERROR_CANDIDATO);
}
}
});
}
protected Dialog onCreateDialog (int id){
switch (id) {
case DIALOG_ERROR_CANDIDATO:
return new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_error)
.setTitle(R.string.error)
.setMessage("The NIF is" +user +DNIWord (user)+ "-")
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
}
return null;
}
}