在spinner中更改Item时将数据加载到Url中异步加载JSON

时间:2016-10-28 09:43:39

标签: java android json spinner ion

这是两个微调器的数组+他们在onCreate使用的声明。

 String semester_list [] = {"1","2","3"};
        String acad_yr  []= {"1","2","3","4","5","6"};
        semester = (Spinner)findViewById(R.id.spinner_semester);
        year_of_study=(Spinner)findViewById(R.id.spinner_year_of_study);

我已使用上述数据填充了两个微调器,然后我使用此格式将所有选定的项目发送到网址,regTester来自之前的Activity

 inn = getIntent();
        regTester = inn.getStringExtra("RegNumber");

        sem = semester.getSelectedItem().toString();
        yr = year_of_study.getSelectedItem().toString();

下面是我的网址。

final String url = Uri.parse("http://10.0.2.2:84/COOPERP/Mobile/Default.aspx").buildUpon()
                    .appendQueryParameter("DataFormat", "StudentsResults")
                    .appendQueryParameter("reg", regTester)
                    .appendQueryParameter("StYr", yr)
                    .appendQueryParameter("sem", sem)
                    .build().toString();

这是我的Full方法,我在下面加载我的JSON数据使用ION库,数据加载但是当我尝试更改两个微调项时,数据不会重新加载。每当我更改微调器中的项目时,如何重新加载它。

public void Load(){
        inn = getIntent();
        regTester = inn.getStringExtra("RegNumber");
        sem = semester.getSelectedItem().toString();
        yr = year_of_study.getSelectedItem().toString();



            final String url = Uri.parse("http://10.0.2.2:84/COOPERP/Mobile/Default.aspx").buildUpon()
                    .appendQueryParameter("DataFormat", "StudentsResults")
                    .appendQueryParameter("reg", regTester)
                    .appendQueryParameter("StYr", yr)
                    .appendQueryParameter("sem", sem)
                    .build().toString();

            //final String url_ ="http://10.0.2.2:84/COOPERP/Mobile/Default.aspx?DataFormat=StudentsResults&reg="+regTester+"&StYr="+yr+"&sem="+sem;



        Toast.makeText(ResultsActivity.this,""+ url,Toast.LENGTH_LONG).show();


            final ProgressDialog pd;
            pd = new ProgressDialog(ResultsActivity.this);
            pd.setMessage("Loading....");
            pd.setCancelable(false);
            pd.show();


            Ion.with(getBaseContext())
                    .load(url)
                    .progressDialog(pd)
                    .as(new TypeToken<List<StudentsResults>>() {
                    })
                    .setCallback(new FutureCallback<List<StudentsResults>>() {

                        @Override
                        public void onCompleted(Exception e, List<StudentsResults> itemList) {
                            final StudentsResultsAdapter adapter = new StudentsResultsAdapter(itemList, getApplicationContext());
                            if (itemList != null) {

                                String Gradept = itemList.get(0).getGradept().toString();
                                String Gpa = itemList.get(0).getGpa().toString();
                                gpa.setText(Gpa);
                                gradept.setText(Gradept);
                                rv.setAdapter(adapter);
                                rv.hasFixedSize();
                                rv.setLayoutManager(new LinearLayoutManager(getBaseContext()));

                                //  rv.setLayoutManager(new LinearLayoutManager(getBaseContext()));

                            } else {
                                rv.setLayoutManager(new LinearLayoutManager(getBaseContext()));
                                Toast.makeText(getApplicationContext(), "No Results found!", Toast.LENGTH_SHORT).show();
                            }

                            pd.dismiss();
                        }
                    });




    }

1 个答案:

答案 0 :(得分:0)

尝试将SELECT Emp_Name, DATE_FORMAT(Emp_DOB, "%d-%b") FROM mldob.tbl_mldob WHERE DATE(DATE_FORMAT(Emp_DOB,'2000-%m-%d')) BETWEEN (DATE_FORMAT(CURDATE(),'2000-%m-%d') - INTERVAL 1 DAY) AND (DATE_FORMAT(CURDATE(),'2000-%m-%d') + INTERVAL 1 DAY) ; 编辑到下方;

Load()

然后进入public void Load(String RegNumber, String Semester , String Year){ final String url = Uri.parse("http://10.0.2.2:84/COOPERP/Mobile/Default.aspx").buildUpon() .appendQueryParameter("DataFormat", "StudentsResults") .appendQueryParameter("reg", RegNumber) .appendQueryParameter("StYr", Year) .appendQueryParameter("sem", Semester) .build().toString(); final ProgressDialog pd; pd = new ProgressDialog(ResultsActivity.this); pd.setMessage("Loading...."); pd.setCancelable(false); pd.show(); Ion.with(getBaseContext()) .load(url) .progressDialog(pd) .as(new TypeToken<List<StudentsResults>>() { }) .setCallback(new FutureCallback<List<StudentsResults>>() { @Override public void onCompleted(Exception e, List<StudentsResults> itemList) { final StudentsResultsAdapter adapter = new StudentsResultsAdapter(itemList, getApplicationContext()); try { if (itemList != null) { String Gradept = itemList.get(0).getGradept().toString(); String Gpa = itemList.get(0).getGpa().toString(); gpa.setText(Gpa); gradept.setText(Gradept); rv.setAdapter(adapter); rv.hasFixedSize(); rv.setLayoutManager(new LinearLayoutManager(getBaseContext())); } else { gpa.setText(null); gradept.setText(null); rv.setAdapter(null); rv.setLayoutManager(new LinearLayoutManager(getBaseContext())); Toast.makeText(getApplicationContext(), "No Results found!", Toast.LENGTH_SHORT).show(); } pd.dismiss(); } catch (Exception ex){ Toast.makeText(getApplicationContext(), "No Results found!", Toast.LENGTH_SHORT).show(); pd.dismiss(); } } }); } onStart()并执行以下操作;

onCreate