Android 带微调器的布局,在Sqlite上保存微调器值后,如何将其显示为默认值使用相同的布局&;基于光标的

Android 带微调器的布局,在Sqlite上保存微调器值后,如何将其显示为默认值使用相同的布局&;基于光标的,android,sqlite,android-layout,spinner,Android,Sqlite,Android Layout,Spinner,使用微调器布局,在Sqlite上保存微调器值后,如何使用与我使用的基于光标的方法相同的布局将其显示/查看为默认值 在我的代码中,clubspinner保存正常,但我已检查了在查看数据库时该值是否已更改,但在使用带微调器的相同布局再次查看时,它仍将微调器的“first”值显示为默认值 在我的代码中,微调器的默认值是“persija”。我已经选择了微调器值并成功地将其更改为“bolton” 但是当重新启动应用程序时,它仍然采用默认的“persija”值 我是android新手,有一个关于微调器的基本

使用微调器布局,在Sqlite上保存微调器值后,如何使用与我使用的基于光标的方法相同的布局将其显示/查看为默认值

在我的代码中,clubspinner保存正常,但我已检查了在查看数据库时该值是否已更改,但在使用带微调器的相同布局再次查看时,它仍将微调器的“first”值显示为默认值

在我的代码中,微调器的默认值是“persija”。我已经选择了微调器值并成功地将其更改为“bolton”

但是当重新启动应用程序时,它仍然采用默认的“persija”值

我是android新手,有一个关于微调器的基本问题:使用“(android.R.layout.simple_spinner_dropdown_item),我们是否能够显示sqlite数据库中的“保存”值,而不仅仅是微调器的第一个默认值

DetailForm.java:

AlmagHelper.java

package com.lm.mobilesalesdb12;

import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;

class AlmagHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME="masteroutletae.db";
    private static final int SCHEMA_VERSION=1;

    public AlmagHelper(Context context) {
        super(context, DATABASE_NAME, null, SCHEMA_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE tblmsdboutlet (_id INTEGER PRIMARY KEY, outletno INT UNIQUE, name TEXT, joindate DATE, club TEXT, poscode INT, ctctper TEXT, phone TEXT, hp TEXT, area TEXT, subarea TEXT);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // no-op, since will not be called until 2nd schema
        // version exists
    }

    public Cursor getAll(String orderBy) {
        return(getReadableDatabase()
                        .rawQuery("SELECT _id, outletno, name, joindate, club, poscode, ctctper, phone, hp, area, subarea FROM tblmsdboutlet ORDER BY "+orderBy,
                                            null));


    }

    public Cursor getById(String id) {
        String[] args={id};

        return(getReadableDatabase()
                        .rawQuery("SELECT _id, outletno, name, joindate, club, poscode, ctctper, phone, hp, area, subarea FROM tblmsdboutlet WHERE _ID=?",
                                            args));
    }

    public void insert(String outletno, String name, String joindate, String club, String poscode, String ctctper,
                                         String phone, String hp, String area, String subarea) {



        ContentValues cv=new ContentValues();

        cv.put("outletno", outletno);
        cv.put("name", name);
        cv.put("joindate", joindate);
        cv.put("club", club);
        cv.put("poscode", poscode);
        cv.put("ctctper", ctctper);
        cv.put("phone", phone);
        cv.put("hp", hp);
        cv.put("area", area);
        cv.put("subarea", subarea);



        getWritableDatabase().insert("tblmsdboutlet", "outletno", cv);
//      getWritableDatabase().insert("tblmsdboutlet", "name", cv);


    }

    public void update(String id, String outletno, String name, String joindate, String club, String poscode, String ctctper,
             String phone, String hp, String area, String subarea) {
        ContentValues cv=new ContentValues();
        String[] args={id};

        cv.put("outletno", outletno);
        cv.put("name", name);
        cv.put("joindate", joindate);
        cv.put("club", club);
        cv.put("poscode", poscode);
        cv.put("ctctper", ctctper);
        cv.put("phone", phone);
        cv.put("hp", hp);
        cv.put("area", area);
        cv.put("subarea", subarea);

        getWritableDatabase().update("tblmsdboutlet", cv, "_ID=?",
                                                                 args);
    }



    public String getOutletno(Cursor c) {
        return(c.getString(1));
    }


    public String getName(Cursor c) {
    return(c.getString(2));
    }

    public String getJoindate(Cursor c) {
        return(c.getString(3));
    }

    public String getClub(Cursor c) {
        return(c.getString(4));
    }

    public String getPoscode(Cursor c) {
        return(c.getString(5));
    }

    public String getCtctper(Cursor c) {
        return(c.getString(6));
    }


    public String getPhone(Cursor c) {
        return(c.getString(7));
    }

    public String getHp(Cursor c) {
        return(c.getString(8));
    }

    public String getArea(Cursor c) {
        return(c.getString(9));
    }

    public String getSubarea(Cursor c) {
        return(c.getString(10));
    }

}
自定义选定侦听器,java

public class CustomOnItemSelectedListener implements OnItemSelectedListener {

    Spinner clubspinner;


    public void onItemSelected(AdapterView<?> parent, View view, int pos,
            long id) {


        Toast.makeText(parent.getContext(), 
                "On Item Select : \n" + parent.getItemAtPosition(pos).toString(),
                Toast.LENGTH_LONG).show();
    }

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

    }

}
公共类CustomOnItemSelectedListener实现OnItemSelectedListener{
微调器;
已选择公共视图(AdapterView父视图、视图、int pos、,
长id){
Toast.makeText(parent.getContext(),
“在项目上选择:\n”+parent.getItemAtPosition(pos.toString(),
Toast.LENGTH_LONG).show();
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
}
DetailLayout.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:id="@+id/widget60"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">


<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    >

    <TableRow>
        <TextView android:text="Outletno:" />
        <EditText android:id="@+id/outletno" 
                  android:inputType="number"
        />
    </TableRow>

    <TableRow>
        <TextView android:text="Name:" />
        <EditText android:id="@+id/name" 

        />
    </TableRow>


    <TableRow>
        <TextView android:text="Joindate:" />
        <EditText android:id="@+id/joindate" />


    </TableRow>


    <TableRow>
        <TextView android:text="Club:" />
        <Spinner 
        android:id="@+id/clubspinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entries="@array/club1_arrays"
        android:prompt="@string/club1_prompt"
        />

    </TableRow>

    <TableRow>
        <TextView android:text="Poscode:" />
        <EditText android:id="@+id/poscode" 
                  android:inputType="number"

        />
    </TableRow>


    <TableRow>
        <TextView android:text="Ctctper:" />
        <EditText android:id="@+id/ctctper" 


        />
    </TableRow>


    <TableRow>
        <TextView android:text="Phone:" />
        <EditText android:id="@+id/phone" 
                  android:inputType="number"
        />
    </TableRow>

    <TableRow>
        <TextView android:text="Hp:" />
        <EditText android:id="@+id/hp" 
                  android:inputType="number"   
        />
    </TableRow>

    <TableRow>
        <TextView android:text="Area:" />
        <EditText android:id="@+id/area" />
    </TableRow>


    <TableRow>
        <TextView android:text="Subarea:" />
        <EditText android:id="@+id/subarea" />
    </TableRow>

    <Button android:id="@+id/btn_save"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Save"
    />

</TableLayout>  

</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Dboutlet</string>


    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="detail_form">DetailForm</string>

    <string name="outletno">Enter Rollno: </string>
    <string name="name">Enter Name: </string>
    <string name="joindate">Enter Marks: </string>
    <string name="club">Enter Rollno: </string>
    <string name="ctctper">Enter Name: </string>
    <string name="phone">Enter Marks: </string>
    <string name="hp">Enter Rollno: </string>
    <string name="area">Enter Name: </string>
    <string name="subarea">Enter Marks: </string>

    <string name="view">View</string>
    <string name="view_all">View All</string>

    <string name="club1_prompt">Choose a club</string>

    <string-array name="club1_arrays">
                <item>Persija </item>
                <item>Chelsea</item>
                <item>PSG</item>
                <item>Arsenal</item>
                <item>Bolton</item>
    </string-array> 



</resources>

String.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:id="@+id/widget60"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">


<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    >

    <TableRow>
        <TextView android:text="Outletno:" />
        <EditText android:id="@+id/outletno" 
                  android:inputType="number"
        />
    </TableRow>

    <TableRow>
        <TextView android:text="Name:" />
        <EditText android:id="@+id/name" 

        />
    </TableRow>


    <TableRow>
        <TextView android:text="Joindate:" />
        <EditText android:id="@+id/joindate" />


    </TableRow>


    <TableRow>
        <TextView android:text="Club:" />
        <Spinner 
        android:id="@+id/clubspinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entries="@array/club1_arrays"
        android:prompt="@string/club1_prompt"
        />

    </TableRow>

    <TableRow>
        <TextView android:text="Poscode:" />
        <EditText android:id="@+id/poscode" 
                  android:inputType="number"

        />
    </TableRow>


    <TableRow>
        <TextView android:text="Ctctper:" />
        <EditText android:id="@+id/ctctper" 


        />
    </TableRow>


    <TableRow>
        <TextView android:text="Phone:" />
        <EditText android:id="@+id/phone" 
                  android:inputType="number"
        />
    </TableRow>

    <TableRow>
        <TextView android:text="Hp:" />
        <EditText android:id="@+id/hp" 
                  android:inputType="number"   
        />
    </TableRow>

    <TableRow>
        <TextView android:text="Area:" />
        <EditText android:id="@+id/area" />
    </TableRow>


    <TableRow>
        <TextView android:text="Subarea:" />
        <EditText android:id="@+id/subarea" />
    </TableRow>

    <Button android:id="@+id/btn_save"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Save"
    />

</TableLayout>  

</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Dboutlet</string>


    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="detail_form">DetailForm</string>

    <string name="outletno">Enter Rollno: </string>
    <string name="name">Enter Name: </string>
    <string name="joindate">Enter Marks: </string>
    <string name="club">Enter Rollno: </string>
    <string name="ctctper">Enter Name: </string>
    <string name="phone">Enter Marks: </string>
    <string name="hp">Enter Rollno: </string>
    <string name="area">Enter Name: </string>
    <string name="subarea">Enter Marks: </string>

    <string name="view">View</string>
    <string name="view_all">View All</string>

    <string name="club1_prompt">Choose a club</string>

    <string-array name="club1_arrays">
                <item>Persija </item>
                <item>Chelsea</item>
                <item>PSG</item>
                <item>Arsenal</item>
                <item>Bolton</item>
    </string-array> 



</resources>

数据库出口
你好,世界!
设置
详细表格
输入Rollno:
输入名称:
输入标记:
输入Rollno:
输入名称:
输入标记:
输入Rollno:
输入名称:
输入标记:
看法
查看所有
选择俱乐部
波斯
切尔西
PSG
兵工厂
博尔顿

通过detailform.java上检查微调器位置的附加方法,它解决了我的问题

>     private void load() {
>       
>           
>           Cursor c=helper.getById(almagId);
>           
>           c.moveToFirst();
>               
>           outletno.setText(helper.getOutletno(c));
>           name.setText(helper.getName(c));
>           joindate.setText(helper.getJoindate(c));
>           poscode.setText(helper.getPoscode(c));
>           ctctper.setText(helper.getCtctper(c));
>           phone.setText(helper.getPhone(c));
>           hp.setText(helper.getHp(c));
>           area.setText(helper.getClub(c));
>           subarea.setText(helper.getSubarea(c));
>           
>           club =(helper.getClub(c));
>     
>           clubspinner=(Spinner)findViewById(R.id.clubspinner);
>           
>           ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.club1_arrays,android.R.layout.simple_spinner_item);
>           
>           adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
>           
>           clubspinner.setAdapter(adapter);
>     
>             String compareValue= club;
>     
>             if (!compareValue.equals(null)) {
>     
>                 int spinnerPostion = adapter.getPosition(compareValue);
>     
>                 clubspinner.setSelection(spinnerPostion);
>     
>                 spinnerPostion = 0;
>     
>             }
>       
>           c.close();
>           
>       }

通过detailform.java上检查微调器位置的附加方法,它解决了我的问题

>     private void load() {
>       
>           
>           Cursor c=helper.getById(almagId);
>           
>           c.moveToFirst();
>               
>           outletno.setText(helper.getOutletno(c));
>           name.setText(helper.getName(c));
>           joindate.setText(helper.getJoindate(c));
>           poscode.setText(helper.getPoscode(c));
>           ctctper.setText(helper.getCtctper(c));
>           phone.setText(helper.getPhone(c));
>           hp.setText(helper.getHp(c));
>           area.setText(helper.getClub(c));
>           subarea.setText(helper.getSubarea(c));
>           
>           club =(helper.getClub(c));
>     
>           clubspinner=(Spinner)findViewById(R.id.clubspinner);
>           
>           ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.club1_arrays,android.R.layout.simple_spinner_item);
>           
>           adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
>           
>           clubspinner.setAdapter(adapter);
>     
>             String compareValue= club;
>     
>             if (!compareValue.equals(null)) {
>     
>                 int spinnerPostion = adapter.getPosition(compareValue);
>     
>                 clubspinner.setSelection(spinnerPostion);
>     
>                 spinnerPostion = 0;
>     
>             }
>       
>           c.close();
>           
>       }