我有一個自定義微調器的問題。實際上,我正在通過查詢加載一個微調,我正在使用一個特定的Asynctask。 在asynctask之後,我應該調用方法setOnItemSelectedListener(),但不起作用:當我啓動應用程序時,該方法未被調用。 我不明白我錯在哪裏......你能幫我嗎?setOnItemSelectedListener()在asynctask後沒有調用
這是我的代碼:
//other code
if (firstpopulate)
{
new LoadSpinnerJobs().execute();
firstpopulate = false;
}
drawerHolder.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3)
{
// do work
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
//other code
public class LoadSpinnerJobs extends AsyncTask<Void, Void, List<SpinnerItem>>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
userList = new ArrayList<SpinnerItem>();
setProgressBarIndeterminateVisibility(true);
}
@Override
protected List<SpinnerItem> doInBackground(Void... voids)
{
DbHelperJob findjob = new DbHelperJob(context);
try
{
QueryBuilder<Job, String> queryBuilder = findjob.getJobDao().queryBuilder();
List<Job> results = queryBuilder.selectColumns("ID_JOB", "NAME_JOB", "TASK_JOB").orderBy("DEFAULT_JOB", false).query();
for (Job a : results)
{
Log.v("result: ", "aggiungo job");
userList.add(new SpinnerItem(String.valueOf(a.getId()), a.getName_job(),a.getName_task()));
}
}
catch (SQLException e)
{
Log.v("exc: ", e.toString());
e.printStackTrace();
}
return userList;
}
@Override
protected void onPostExecute(List<SpinnerItem> result)
{
super.onPostExecute(result);
Log.v("post: ", "setto spinner");
CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(context,R.layout.custom_spinner_item, userList);
drawerHolder.spinner.setAdapter(adapter);
setProgressBarIndeterminateVisibility(false);
}
}
您是否嘗試過調試它。究竟出了什麼問題?有沒有例外,或聽衆是否不開火? – Ridcully
沒有例外。 :( 我試圖調試它。沒有問題。簡單地說,setOnItemSelectedListener()被跳過了... – user3449772
是的,我認爲聽衆只是不開火... – user3449772