我有一個EditText和(瞬間2按鈕)的活動。當按下按鈕時,來自EditText的數據將被檢查爲空或空字符串。如果是的話應該顯示AlertDialog。這應該重複,直到TextEdit的結果不是空的。 只要我沒有任何活動中的進一步處理,這工作正常。如果我有進一步的隱患,則不會顯示Alertdialog。一步一步dubugging顯示申請進入檢查,創建Alertdialog但它沒有顯示,而是執行代碼中的下一條指令。所以這沒有意義。應用程序必須在顯示Alertdialog的位置停止處理。 一旦收到一個非空字符串,就應該針對具有各種SQL注入字符串的文本文件進行檢查,並提出一個顯示測試進度的Progressdialog。如果測試結果爲肯定,它應返回到EditText以允許更正數據。 到目前爲止,所有按鈕的行爲都是相同的。所以我相信這將是爲這些行爲創建一個自己的(內部)類的最佳方式。 進一步的行動(尚未實施)應該是:一個按鈕然後會調用另一個活動,要求手動完成數據,其他活動將嘗試從各種互聯網資源中獲取缺失的數據。並在另一項活動中顯示結果,以便選擇正確的數據。完整的數據將被髮送到數據庫。 (針對SQL注入字符串測試的原因之一)Alertdialog沒有顯示
下面是代碼:
public class BlahverwaltungDateneingabeActivity extends Activity {
public String vtitel=null; //Variable, der der Wert des Texteingabefeldes zugewiesen werden soll
public String vtitel_1 = null; //Variable für Stringmanipulation
private EditText input_vtitel; //Texteingabefeld
public static Boolean inject_2=false;
final Context context_1=this;
Toast einToast;
// private String filename=getString(R.string.Tempfile_fuer_Blahdaten); // Temporäres File für Blahdaten
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blahverwaltung_dateneingabe_1);
Button manuellButton = (Button) findViewById(R.id.manuell_button);
Button ofdbButton = (Button) findViewById(R.id.blah_button);
//OnClicklistener erzeugen
manuellButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
input_vtitel = (EditText) findViewById(R.id.Blahtitel); //Texteingabefeld initialisieren
vtitel = input_vtitel.getText().toString(); //Texteingabe String zuweisen
if (vtitel.equals(null) || vtitel.equals("")) {
AlertDialog.Builder adb_1 = new AlertDialog.Builder(context_1); //Alertdialog wenn Texteingabe leer
adb_1.setTitle(R.string.Nullstring); //Alertdialgo Titel setzen
adb_1.setMessage(R.string.Nullstring_1); //AlertNachricht setzen
adb_1.setCancelable(false); //kann nicht durch Back abgebrochen werden
adb_1.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { //OnClickListener erzeugen
public void onClick(DialogInterface dialog, int which) { //Activity neu starten
dialog.dismiss();
if (Build.VERSION.SDK_INT >= 11) { //Methode zum Neustart in Abhängigkeit vom SDK wählen
recreate();
} else {
Intent in_1 = getIntent();
overridePendingTransition(0, 0);
in_1.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(in_1);
}
}
});
AlertDialog ad_1 = adb_1.create(); //Alertdialig erzeugen
ad_1.show();
//Alertdialog anzeigen
}
InjectionDialog id_1= new InjectionDialog(BlahverwaltungDateneingabeActivity.this);
id_1.execute(vtitel);
try {
inject_2=id_1.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
// vtitel_1 = vtitel.replace(" ", "+"); //Leerzeichen durch "+" ersetzen
/*
try {
outputstream_1 = openFileOutput(filename, Context.MODE_PRIVATE);
outputstream_1.write(vtitel.getBytes());
outputstream_1.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
*/
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.blahverwaltung_dateneingabe, menu);
return true;
}
}
如果你提供幫助,請解釋儘可能多的,我是一個Java/Android的新手,有時真的不充分理解我在做什麼。學習書籍和互聯網資源通常不會有幫助。我能夠採用提供的解決方案,但我也想明白爲什麼這樣做,代碼在做什麼。
順便說一句:正如我上面提到的數據可能發送到interent,那麼如何確保沒有html黑客入侵,跨腳本腳本的java腳本,php攻擊代碼是否在數據發送時? aRe還有一些comon字符串,我可以檢查數據字符串?