hi guys,
could you do me a favour and take a look at the following code and see what i'm missing.. been staring at it for a while now and can't figure out why it's not working (note coding knowledge is only 4 days of java+xml.. so i'm sure i'm missing something rather obvious)
Basically the code is supposed to save the txt from the input field and then output it back to that field if you leave/come back to the screen! buuut nada!
thanks for any help and advice!
----------
could you do me a favour and take a look at the following code and see what i'm missing.. been staring at it for a while now and can't figure out why it's not working (note coding knowledge is only 4 days of java+xml.. so i'm sure i'm missing something rather obvious)
Basically the code is supposed to save the txt from the input field and then output it back to that field if you leave/come back to the screen! buuut nada!
thanks for any help and advice!
----------
Code:
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class review_report extends Activity {
public static final String CarDetails= "";
public static final String CarDetails_vehi_model = "";
public static final String CarDetails_veh_year = "";
public static final String CarDetails_veh_make = "";
public static final String CarDetails_veh_licnum = "";
public static final String CarDetails_veh_col = "";
public static final String DEBUG_TAG = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.fill_report2);
// setting up back button + sound
final MediaPlayer buttonSound = MediaPlayer.create(review_report.this,
R.raw.clicknoise);
buttonSound.start();
Button backbutton = (Button) findViewById(R.id.backbutton);
backbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent(
"com.belairdirect.belairdirectaccidenthelper.MAIN"));
}
});
//end setting up back button
//starting input data gathering
final EditText modelText = (EditText) findViewById(R.id.TEXT_model);
String vehi_model = modelText.getText().toString();
// saving input data
SharedPreferences CarDetails;
CarDetails = getSharedPreferences(CarDetails_vehi_model, Context.MODE_PRIVATE);
//no idea
Editor editor = CarDetails.edit();
editor.putString(CarDetails_vehi_model, vehi_model);
editor.commit();
//supposed to display the field if string has txt in it
final EditText ModelText =
(EditText) findViewById(R.id.TEXT_model);
if (CarDetails.contains(CarDetails_vehi_model)) {
ModelText.setText(CarDetails.getString(
CarDetails_vehi_model, ""));
}
//save all data on page destroy
onDestroy();
{
Log.d(DEBUG_TAG, "Car Model is:"
+ CarDetails.getString(CarDetails_vehi_model, "Not set"));
super.onDestroy();
}
}
}

