hiho
ich bastel gerade an einer console und habe das problem, das die prüfung immer um 1 versetzt ist.
prüfe ich eingabe b nachdem ich eingabe a geprüft hatte, gibt er mir bei der ersten prüfen von b, den wert von a aus. erst bei der 2. prüfung gibt er mir den wert von b aus.
wo liegt mein fehler?
ich bastel gerade an einer console und habe das problem, das die prüfung immer um 1 versetzt ist.
prüfe ich eingabe b nachdem ich eingabe a geprüft hatte, gibt er mir bei der ersten prüfen von b, den wert von a aus. erst bei der 2. prüfung gibt er mir den wert von b aus.
wo liegt mein fehler?
Java:
package org.world_hack.s1.app;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import org.json.JSONArray;
import org.json.JSONObject;
public class activity_console_copy extends Fragment implements View.OnClickListener{
View rootview;
Fragment objFragment;
CheckAttackLocalStore checkAttackLocalStore;
ConsoleLocalStore consoleLocalStore;
UserLocalStore userLocalStore;
int uid;
String usersecu, userid, statusmsg, neu, set;
EditText input;
LayoutInflater inflater;
RelativeLayout relativeLayout;
TableLayout ll;
public static final int CONNECTION_TIMEOUT = 1000 * 30;
public static final String SERVER_ADRESS = "http://world-hack.org";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.activity_console, container, false);
relativeLayout = (RelativeLayout)rootview.findViewById(R.id.layout);
input = null;
Button btnSend = (Button)rootview.findViewById(R.id.btnSend);
btnSend.setOnClickListener(this);
AlertDialog.Builder dialogBuilders = new AlertDialog.Builder(getActivity());
dialogBuilders.create();
input = (EditText) rootview.findViewById(R.id.input);
Console consolecheck= new Console(input.toString());
fetchConsole(consolecheck);
consoleLocalStore = new ConsoleLocalStore(getActivity());
userLocalStore = new UserLocalStore(getActivity());
User user = userLocalStore.getLoggedInUser();
uid = user.uid;
userid = Integer.toString(user.uid);
usersecu = user.usersecu;
checkAttackLocalStore = new CheckAttackLocalStore(getActivity());
return rootview;
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnSend:
checkConsoleInput();
displayConsoleDetails();
input.setText("");
break;
}
}
private void fetchCheckAttacks(CheckAttack checkAttack){
consoleLocalStore = new ConsoleLocalStore(getActivity());
CheckAttackRequests checkAttackRequests = new CheckAttackRequests(getActivity());
checkAttackRequests.fetchCheckAttackDataInBackground(checkAttack, new GetCheckAttackCallback() {
@Override
public void done(CheckAttack returnedCheckAttack) {
if (returnedCheckAttack == null) {
showErrorMessage("Fehler beim laden der Daten");
} else {
checkAttackLocalStore.storeCheckAttackData(returnedCheckAttack);
}
}
});
}
public void checkConsoleInput() {
consoleLocalStore = new ConsoleLocalStore(getActivity());
Console sconsole = consoleLocalStore.getUserConsole();
Console returnedConsole;
String save_input = input.getText().toString();
String check = sconsole.check;
String sentence = (save_input.equals("") ? sconsole.newc : save_input );
String search_check = "check this" ;
if (sentence.toLowerCase().indexOf(search_check.toLowerCase()) != -1 ){
if(check.equals("") || check.equals(null) ) {
CheckAttack checkattack = new CheckAttack();
fetchCheckAttacks(checkattack);
checkAttackLocalStore = new CheckAttackLocalStore(this.getActivity());
CheckAttack checkAttack1 = checkAttackLocalStore.getUserCheckAttack();
String checkAttack2 = checkAttack1.checkAttack;
if(checkAttack2.equals("checked")) {
neu = "Check This \n" +
"Done";
check = "checked";
}else {
neu = "Check This \n" +
"Error: " + checkAttack2;
check = "";
}
}
}else {
neu = "unbekannter Befehl";
System.out.println("not found");
}
String output = (neu != null ? "{"+ neu + "}," : "");
String oldoutputx = "["+output+"]";
oldoutputx = oldoutputx.replace("},]", "},null]");
oldoutputx = oldoutputx.replace("}]", "},null]");
oldoutputx = oldoutputx.replace("},[{", "},{");
oldoutputx = oldoutputx.replace("}[{", "},{");
oldoutputx = oldoutputx.replace("{", "{\"output\":\"");
oldoutputx = oldoutputx.replace("}", "\"}");
oldoutputx = oldoutputx.replace(":\":", ":");
oldoutputx = oldoutputx.replace("\"\"", "\"");
String oldoutput = oldoutputx.replace("\"output\":\"\"output\"", "\"output\":\"");
String old = oldoutput;
returnedConsole = new Console(old, neu, check);
consoleLocalStore.storeConsoleData(returnedConsole);
}
private void fetchConsole(Console console) {
ConsoleRequests consoleRequests = new ConsoleRequests(getActivity());
consoleRequests.fetchConsolesDataInBackground(console, new GetConsoleCallback() {
@Override
public void done(JSONArray returnedConsole) {
if (returnedConsole == null) {
displayConsoleDetails();
} else {
consoleLocalStore.storeConsoleData(returnedConsole);
displayConsoleDetails();
}
}
}, set);
}
private void showErrorMessage(String text){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
dialogBuilder.setMessage(text);
dialogBuilder.setPositiveButton("OK", null);
dialogBuilder.show();
}
private void displayConsoleDetails(){
JSONArray jArray;
consoleLocalStore = new ConsoleLocalStore(getActivity());
Console sconsole = consoleLocalStore.getUserConsole();
String daten = sconsole.output;
Console consolex;
try {
jArray = new JSONArray(daten);
for (int i = 0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
final String outputy = jObject.getString("output");
String startneuString = outputy.replace("[", "");
String outputx = startneuString.replace("]", "");
String oldz = sconsole.oldc;
oldz = oldz.replace("[", "");
oldz = oldz.replace("]", "");
String neu = outputx;
String old = oldz;
String check = sconsole.check;
consolex = new Console(old, neu, outputx, check);
ll = (TableLayout) rootview.findViewById(R.id.displayLinear);
TableRow row = new TableRow(getActivity());
consoleLocalStore.storeConsoleData(consolex);
LayoutInflater inflater = getLayoutInflater(getArguments());
View theInflatedView = inflater.inflate(R.layout.activity_consolex,
null);
TextView attid = (TextView) theInflatedView.findViewById(R.id.output);
System.getProperty("line.separator");
attid.setText(String.valueOf(consolex.output));
attid = new TextView(getActivity());
row.addView(attid);
row.setGravity(Gravity.CENTER_HORIZONTAL);
row.addView(theInflatedView);
ll.addView(row, i);
}
} catch (org.json.JSONException e) {
System.out.println(e);
}
}
}