从前一个活动的微调器复制值时缺少文本

时间:2014-04-06 23:33:56

标签: android sqlite missing-data

需要你的帮助..我做了一个活动,其中用户键入的个人资料详细信息保存在sqlite中,包括来自微调器的值。然后,如果用户返回编辑配置文件详细信息,他们可以更改除保存的微调器的值之外的所有内容,这些值仅显示为textview。我的问题是,当我尝试进行editprofile活动时,最后一个微调器(textWeight)的值不会出现。有人可以帮忙检查我做错了什么吗?这是我的代码。谢谢!

NewProfile.java

public class NewProfile extends Activity {

EditText profileName, profileDOB, profileSex, profileWeight, profileHeight;
Spinner workoutSpinner, levelSpinner, weightSpinner;
TextView textWorkout, textLevel, textWeight;
DBController controller = new DBController(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newdata);
    profileName = (EditText) findViewById(R.id.etName);
    profileDOB = (EditText) findViewById(R.id.etDOB);
    profileSex = (EditText) findViewById(R.id.etSex);
    profileWeight = (EditText) findViewById(R.id.etWeight);
    profileHeight = (EditText) findViewById(R.id.etHeight);
    workoutSpinner = (Spinner) findViewById(R.id.spinWorkout);
    levelSpinner = (Spinner) findViewById(R.id.spinLevel);
    weightSpinner = (Spinner) findViewById(R.id.spinWeight);
    textWorkout = (TextView) findViewById(R.id.tvWorkout);
    textLevel = (TextView) findViewById(R.id.tvLevel);      
    textWeight = (TextView) findViewById(R.id.tvWeight);

    chooseWorkout();
    chooseLevel();
    chooseWeight();
}

private void startingpointActivity(View view) {
    // TODO Auto-generated method stub
    Intent objIntent = new Intent(getApplicationContext(),
            StartingPoint.class);
    startActivity(objIntent);
    finish();
}

private void chooseWorkout() {
    // TODO Auto-generated method stub

    ArrayAdapter<CharSequence> workoutadapter = ArrayAdapter
            .createFromResource(this, R.array.saWorkout,
                    android.R.layout.simple_spinner_item);
    workoutadapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    workoutSpinner.setAdapter(workoutadapter);
    workoutSpinner.setOnItemSelectedListener(new workoutOnClickListener());

}

public class workoutOnClickListener implements OnItemSelectedListener {

    @Override
    public void onItemSelected(AdapterView<?> parent, View v, int pos,
            long id) {
        // TODO Auto-generated method stub

        parent.getItemAtPosition(pos);

        if (pos == 0) {
            chooseLevel();
            levelSpinner.setClickable(true);
            weightSpinner.setClickable(true);
        } else if (pos != 0) {
            levelSpinner.setClickable(false);
            weightSpinner.setClickable(false);
            Toast.makeText(
                    getApplicationContext(),
                    "Wollaaaa! Only Program 1 is available for this moment. Sorry..  :)",
                    Toast.LENGTH_LONG).show();
        }
        String selectWorkout = parent.getItemAtPosition(pos).toString();
        textWorkout.setText(selectWorkout);

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

}

private void chooseLevel() {
    // TODO Auto-generated method stub

    ArrayAdapter<CharSequence> leveladapter = ArrayAdapter
            .createFromResource(this, R.array.saLevel,
                    android.R.layout.simple_spinner_item);
    leveladapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    levelSpinner.setAdapter(leveladapter);
    levelSpinner.setOnItemSelectedListener(new levelOnClickListener());

}
public class levelOnClickListener implements OnItemSelectedListener {

    @Override
    public void onItemSelected(AdapterView<?> parent, View v, int pos,
            long id) {
        // TODO Auto-generated method stub

        String selectLevel = parent.getItemAtPosition(pos).toString();
        textLevel.setText(selectLevel);

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

}
private void chooseWeight() {
    // TODO Auto-generated method stub

    ArrayAdapter<CharSequence> weightadapter = ArrayAdapter
            .createFromResource(this, R.array.saWeight,
                    android.R.layout.simple_spinner_item);
    weightadapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    weightSpinner.setAdapter(weightadapter);
    weightSpinner.setOnItemSelectedListener(new weightOnClickListener());

}
public class weightOnClickListener implements OnItemSelectedListener {

    @Override
    public void onItemSelected(AdapterView<?> parent, View v, int pos,
            long id) {
        // TODO Auto-generated method stub

        String selectWeight = parent.getItemAtPosition(pos).toString();
        textWeight.setText(selectWeight);
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

}

public void addNewProfile(View view) {
    HashMap<String, String> queryValuesMap = new HashMap<String, String>();
    queryValuesMap.put("profileName", profileName.getText().toString());
    queryValuesMap.put("profileDOB", profileDOB.getText().toString());
    queryValuesMap.put("profileSex", profileSex.getText().toString());
    queryValuesMap.put("profileWeight", profileWeight.getText().toString());
    queryValuesMap.put("profileHeight", profileHeight.getText().toString());
    queryValuesMap.put("textWorkout", textWorkout.getText().toString());
    queryValuesMap.put("textLevel", textLevel.getText().toString());
    queryValuesMap.put("textWeighht", textWeight.getText().toString());
    controller.insertProfile(queryValuesMap);
    this.startingpointActivity(view);
}

}

EditProfile.java

public class EditProfile extends Activity {
EditText profileName, profileDOB, profileSex, profileWeight, profileHeight;
TextView textWorkout, textLevel, textWeight;
DBController controller = new DBController(this);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.editdata);
    profileName = (EditText) findViewById(R.id.etName);
    profileDOB = (EditText) findViewById(R.id.etDOB);
    profileSex = (EditText) findViewById(R.id.etSex);
    profileWeight = (EditText) findViewById(R.id.etWeight);
    profileHeight = (EditText) findViewById(R.id.etHeight);
    textWorkout = (TextView) findViewById(R.id.tvCurrentWorkout);
    textLevel = (TextView) findViewById(R.id.tvCurrentLevel);
    textWeight = (TextView) findViewById(R.id.tvCurrentWeight);

    Intent objIntent = getIntent();
    String profileId = objIntent.getStringExtra("profileId");
    Log.d("Reading: ", "Reading all profile..");
    HashMap<String, String> profileList = controller
            .getProfileInfo(profileId);


    if (profileList.size() != 0) {
        profileName.setText(profileList.get("profileName"));
        profileDOB.setText(profileList.get("profileDOB"));
        profileSex.setText(profileList.get("profileSex"));
        profileWeight.setText(profileList.get("profileWeight"));
        profileHeight.setText(profileList.get("profileHeight"));
        textWorkout.setText(profileList.get("textWorkout"));
        textLevel.setText(profileList.get("textLevel"));
        textWeight.setText(profileList.get("textWeight"));

    }
}

public void editProfile(View view) {

    HashMap<String, String> queryValuesMap = new HashMap<String, String>();
    profileName = (EditText) findViewById(R.id.etName);
    profileDOB = (EditText) findViewById(R.id.etDOB);
    profileSex = (EditText) findViewById(R.id.etSex);
    profileWeight = (EditText) findViewById(R.id.etWeight);
    profileHeight = (EditText) findViewById(R.id.etHeight);
    textWorkout = (TextView) findViewById(R.id.tvCurrentWorkout);
    textLevel = (TextView) findViewById(R.id.tvCurrentLevel);
    textWeight = (TextView) findViewById(R.id.tvCurrentWeight);

    Intent objIntent = getIntent();
    String profileId = objIntent.getStringExtra("profileId");

    queryValuesMap.put("profileId", profileId);
    queryValuesMap.put("profileName", profileName.getText().toString());
    queryValuesMap.put("profileDOB", profileDOB.getText().toString());
    queryValuesMap.put("profileSex", profileSex.getText().toString());
    queryValuesMap.put("profileWeight", profileWeight.getText().toString());
    queryValuesMap.put("profileHeight", profileHeight.getText().toString());
    queryValuesMap.put("textWorkout", textWorkout.getText().toString());
    queryValuesMap.put("textLevel", textLevel.getText().toString());
    queryValuesMap.put("textWeight", textWeight.getText().toString());
    controller.updateProfile(queryValuesMap);
    this.startingpointActivity(view);

}

public void removeProfile(View view) {
    Intent objIntent = getIntent();
    String profileId = objIntent.getStringExtra("profileId");
    controller.deleteProfile(profileId);
    this.removeId(view);

}

public void startingpointActivity(View view) {
    Intent objIntent = new Intent(getApplicationContext(),
            StartingPoint.class);
    startActivity(objIntent);
    finish();
}

public void removeId(View view) {
    Intent theIntent = new Intent(getApplicationContext(), Profile.class);
    startActivity(theIntent);
    finish();
}
}

0 个答案:

没有答案