Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从mySql数据库填充spinner_Android_Mysql - Fatal编程技术网

Android 如何从mySql数据库填充spinner

Android 如何从mySql数据库填充spinner,android,mysql,Android,Mysql,我如何填充它,我的应用程序中有两个微调器,一个用于省,另一个用于市,当我选择Gauteng in Province微调器时,我希望我的第二个微调器显示约翰内斯堡、比勒陀利亚、Centurion,如果我选择KZN in Province,我希望我的第二个微调器显示Maritsburg和德班 我使用mySql数据库,我有省表和市表。 这是我的省表(idprovince,provincename) 这是我的城市表(idcity、cityname、province\u idprovince) 我将感谢您

我如何填充它,我的应用程序中有两个微调器,一个用于省,另一个用于市,当我选择Gauteng in Province微调器时,我希望我的第二个微调器显示约翰内斯堡、比勒陀利亚、Centurion,如果我选择KZN in Province,我希望我的第二个微调器显示Maritsburg和德班

我使用mySql数据库,我有省表和市表。 这是我的省表(idprovince,provincename)

这是我的城市表(idcity、cityname、province\u idprovince)


我将感谢您的帮助。

您应该按照一些教程(如本教程)查看如何加载微调器

好的,然后您应该查看一些教程以了解微调器的基本知识 做了那件事之后

第一步:从数据库中获取数据,并使用适配器将其设置为第一个微调器


第2步:在第一个微调器的OnItemSelected事件中,您还必须设置第二个适配器(根据所选项目从db获取数据,并使用适配器将其设置为第二个微调器)

以下是一个示例。这里我使用SAX解析从服务器获得了详细信息。这里District_districtname和District_districtid是存储服务器详细信息的ArrayList

Spinner sp1, sp2;
ArrayList<String> loc = new ArrayList<String>();
static ArrayList<String> mov = new ArrayList<String>();

ArrayAdapter<String> ad = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, district_districtname);
    // apply the Adapter:
    sp1.setAdapter(ad);
    sp1.clearFocus();

    sp1.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {

            int pos = sp1.getSelectedItemPosition();
            selecteddistrict = district_districtname.get(pos);

            loc.clear();
            for (int i = 0; i < district_districtname.size(); i++) {

                if (district_districtname.get(i).equals(selecteddistrict)) {

                    districtid = district_districtid.get(i);
                    for (int j = 0; j < locality_localityname.size(); j++) {

                        if (locality_districtid.get(j).equals(districtid)) {

                            loc.add(locality_localityname.get(j));

                        }
                    }
                }
            }


            sp2 = (Spinner) findViewById(R.id.Spinner01);

    ArrayAdapter<String> ad2 = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, loc);
    // apply the Adapter:
    sp2.setAdapter(ad2);

    sp2.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
微调器sp1、sp2;
ArrayList loc=新的ArrayList();
静态ArrayList mov=新ArrayList();
ArrayAdapter ad=新的ArrayAdapter(此,
android.R.layout.simple\u微调器\u项目,地区名称);
//应用适配器:
设置适配器(ad);
sp1.clearFocus();
setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
整数arg2,长arg3){
int pos=sp1.getSelectedItemPosition();
selecteddistrict=district\u districtname.get(pos);
loc.clear();
对于(int i=0;i

}

这是一个你要求人们帮助你解决你可能遇到的编码问题的地方。这不是一个你要求为你做工作的地方。请看这里应该问的问题类型:我很困惑。你的意思是你使用
sqlite
还是使用
mysql
服务器客户端架构你的问题是什么很不清楚你尝试了什么,你到底想要什么?发布代码员而不是数据库?@kaluwila我不知道从哪里开始这就是我寻求帮助的原因
1  Johannesburg    1 
2   pretoria    1 
3   Centurion   1 
4   Bloemfontein    2 
5   Welkom  2 
6   Polokwane   3 
7   Phalaborwa  3 
8   Potgiersrus 3 
9   Tzaneen 3 
10  Kimberley   4 
11  Upington    4 
12  Mafikeng    5 
13  Klerksdorp  5 
14  Mmabatho    5 
15  Potchefstroom   5 
16  Brits   5 
17  Cape-Town   6 
18  Stellenbosch    6 
19  George  6 
20  Saldhana-Bay    6 
21  Bisho   7 
22  Port-Elizabeth  7 
23  East-London 7 
24  Pietermaritzburg    8 
25  Durban  8 
26  Ulundi  8 
27  Richards-Bay    8 
28  Newcastle   8 
29  Nelspruit   9 
30  Witbank 9 
31  Middleburg  9 
32  Ermelo  9
Spinner sp1, sp2;
ArrayList<String> loc = new ArrayList<String>();
static ArrayList<String> mov = new ArrayList<String>();

ArrayAdapter<String> ad = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, district_districtname);
    // apply the Adapter:
    sp1.setAdapter(ad);
    sp1.clearFocus();

    sp1.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {

            int pos = sp1.getSelectedItemPosition();
            selecteddistrict = district_districtname.get(pos);

            loc.clear();
            for (int i = 0; i < district_districtname.size(); i++) {

                if (district_districtname.get(i).equals(selecteddistrict)) {

                    districtid = district_districtid.get(i);
                    for (int j = 0; j < locality_localityname.size(); j++) {

                        if (locality_districtid.get(j).equals(districtid)) {

                            loc.add(locality_localityname.get(j));

                        }
                    }
                }
            }


            sp2 = (Spinner) findViewById(R.id.Spinner01);

    ArrayAdapter<String> ad2 = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, loc);
    // apply the Adapter:
    sp2.setAdapter(ad2);

    sp2.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {