Android 保存微调器并将其用于其他活动

Android 保存微调器并将其用于其他活动,android,save,spinner,Android,Save,Spinner,我试着使用这些例子并阅读那些我认为与我的项目相关的链接,但所有这些链接的结构都与我的不同。希望有人能帮忙 我的NewProfile.java类中有3个微调器。在本课程中,用户可以输入他们的个人资料,还可以根据用户的兴趣选择训练类型。保存配置文件文本输入没有问题。但是我在保存用户选择的微调器值时遇到问题。以下是我的代码 NewProfile.java public class NewProfile extends Activity { EditText profileName, profileD

我试着使用这些例子并阅读那些我认为与我的项目相关的链接,但所有这些链接的结构都与我的不同。希望有人能帮忙

我的NewProfile.java类中有3个微调器。在本课程中,用户可以输入他们的个人资料,还可以根据用户的兴趣选择训练类型。保存配置文件文本输入没有问题。但是我在保存用户选择的微调器值时遇到问题。以下是我的代码

NewProfile.java

public class NewProfile extends Activity {

EditText profileName, profileDOB, profileSex, profileWeight, profileHeight;
Spinner workoutspinner, levelspinner, weightplan1, weightplan2,
        weightplan3;
TextView display;
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);

    chooseWorkout();
    chooseLevel();
    chooseWeight1();
    chooseWeight2();
    chooseWeight3();
}

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());
    controller.insertProfile(queryValuesMap);
    this.startingpointActivity(view);
}

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

    workoutspinner = (Spinner) findViewById(R.id.spinWorkout);
    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());

}

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

    levelspinner = (Spinner) findViewById(R.id.spinLevel);
    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());

}

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

    weightplan1 = (Spinner) findViewById(R.id.spinWeight);
    ArrayAdapter<CharSequence> weightadapter1 = ArrayAdapter
            .createFromResource(this, R.array.saWeight1,
                    android.R.layout.simple_spinner_item);
    weightadapter1
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    weightplan1.setAdapter(weightadapter1);

}

private void chooseWeight2() {
    // TODO Auto-generated method stub
    weightplan2 = (Spinner) findViewById(R.id.spinWeight);
    ArrayAdapter<CharSequence> weightadapter2 = ArrayAdapter
            .createFromResource(this, R.array.saWeight2,
                    android.R.layout.simple_spinner_item);
    weightadapter2
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    weightplan2.setAdapter(weightadapter2);

}
private void chooseWeight3() {
    // TODO Auto-generated method stub
    weightplan3 = (Spinner) findViewById(R.id.spinWeight);
    ArrayAdapter<CharSequence> weightadapter3 = ArrayAdapter
            .createFromResource(this, R.array.saWeight3,
                    android.R.layout.simple_spinner_item);
    weightadapter3
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    weightplan3.setAdapter(weightadapter3);
}


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);
            weightplan1.setClickable(true);
            weightplan2.setClickable(true);
            weightplan3.setClickable(true);
        } else if (pos != 0){
            levelspinner.setClickable(false);
            weightplan1.setClickable(false);
            weightplan2.setClickable(false);
            weightplan3.setClickable(false);
            Toast.makeText(getApplicationContext(),
                    "Wollaaaa! Only Program 1 is available for this moment. Sorry..  :)",
                    Toast.LENGTH_LONG).show();
        }

    }

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

    }

}

public class levelOnClickListener 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) {
            chooseWeight1();
        } else if (pos == 1){
            chooseWeight2();
        } else if (pos == 2){
            chooseWeight3();

        }

    }

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

    }

}
}
public类NewProfile扩展活动{
EditText profileName、profileDOB、profileSex、profileWeight、profileHeight;
旋转器训练旋转器、水平旋转器、重量计划1、重量计划2、,
权重计划3;
文本视图显示;
DBController=新的DBController(此);
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
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);
选择workout();
chooseLevel();
选择weight1();
选择weight2();
选择weight3();
}
公共void addNewProfile(视图){
HashMap queryValuesMap=新HashMap();
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());
controller.insertProfile(queryValuesMap);
此.startingpoint活动(视图);
}
私有void起始点活动(视图){
//TODO自动生成的方法存根
Intent objIntent=新的Intent(getApplicationContext(),
起始点(类);
星形触觉;
完成();
}
private void chooseWorkout(){
//TODO自动生成的方法存根
workoutspinner=(Spinner)findViewById(R.id.spinWorkout);
ArrayAdapter workoutadapter=ArrayAdapter
.createFromResource(此,R.array.saWorkout,
android.R.layout.simple\u微调器(项目);
修井适配器
.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
workoutspinner.setAdapter(workoutadapter);
workoutspinner.setOnItemSelectedListener(新的workoutOnClickListener());
}
私有void选择器级别(){
//TODO自动生成的方法存根
levelspinner=(微调器)findViewById(R.id.spinLevel);
ArrayAdapter leveladapter=ArrayAdapter
.createFromResource(此,R.array.saLevel,
android.R.layout.simple\u微调器(项目);
水平适配器
.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
levelspinner.setAdapter(leveladapter);
setOnItemSelectedListener(新的levelOnClickListener());
}
私有void选择权重1(){
//TODO自动生成的方法存根
weightplan1=(微调器)findViewById(R.id.spinWeight);
ArrayAdapter权重适配器1=ArrayAdapter
.createFromResource(这个,R.array.saWeight1,
android.R.layout.simple\u微调器(项目);
权重适配器1
.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
权重计划1.设置适配器(权重适配器1);
}
私有void chooseWeight2(){
//TODO自动生成的方法存根
weightplan2=(微调器)findViewById(R.id.spinWeight);
ArrayAdapter权重适配器2=ArrayAdapter
.createFromResource(这个,R.array.saWeight2,
android.R.layout.simple\u微调器(项目);
权重适配器2
.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
权重计划2.设置适配器(权重适配器2);
}
私有void chooseWeight3(){
//TODO自动生成的方法存根
weightplan3=(微调器)findViewById(R.id.spinWeight);
ArrayAdapter权重适配器3=ArrayAdapter
.createFromResource(此,R.array.saWeight3,
android.R.layout.simple\u微调器(项目);
权重适配器3
.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
权重计划3.设置适配器(权重适配器3);
}
公共类WorkUnclicklListener实现OnItemSelectedListener{
@凌驾
已选择公共位置(AdapterView父视图、视图v、内部位置、,
长id){
//TODO自动生成的方法存根
父项。getItemAtPosition(pos);
如果(位置==0){
chooseLevel();
levelspinner.setClickable(真);
权重计划1.可点击设置(真);
权重计划2.可点击设置(真);
权重计划3.可点击设置(真);
}否则如果(位置!=0){
levelspinner.setClickable(错误);
权重计划1.可点击设置(假);
权重计划2.可点击设置(假);
权重计划3.可点击设置(假);
Toast.makeText(getApplicationContext(),
“Wollaaaa!目前只有程序1可用。抱歉..:)”,
Toast.LENGTH_LONG).show();
}
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
}
公共类levelOnClickListener实现OnItemSelectedListener{
@凌驾
已选择公共位置(AdapterView父项、视图v、内部位置、长id){
//TODO自动生成的方法存根
父项。getItemAtPosition(pos);
如果(位置==0){
选择weight1();
}否则如果(位置==1){
选择weight2();
}否则如果(位置==2){
选择weight3();
}
}
@凌驾
mySpinner.setSelection(arrayAdapter.getPosition("Category 2")); //This assumes that "Category 2" exists in your spinner list.
String Text = mySpinner.getSelectedItem().toString(); 
test_string=shared_preferences.getString("test_key", "Default");