0
這是兩個spinners的數組+他們在onCreate
中使用的聲明。在更改微調器中的項目時將數據加載到Url中異步加載JSON
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);
我已填充了兩個微調器上面的數據,然後我採用這種格式發送所有選定項目到URL中,regTester
從以前Activity
了
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
下面
是我的URL。
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();
這是我的全部方法,現在用在加載我下面的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®="+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();
}
});
}
你需要打電話給你的load()方法對微調的onItemSelected()方法,所以當你改變任何微調的值,它會調用 – Vickyexpert
嘿Vickyexpert,感謝您的回覆,但我仍然困惑,我該怎麼當它們在'Load'方法內時,調用'Load'方法到每個spinners上。請告訴我我該怎麼做 –