我有一個活動,有一個微調選擇一天和一個列表,應顯示列表項目根據從微調選擇的項目列表項目。當一個微調項目被選中列表不會改變
我在查詢sqlite數據庫,不同的查詢必須用於微調器上選擇的不同項目。
我正在使用一個簡單的遊標適配器。
我爲我的微調器設置了onItemSelected(AdapterView<?>
parent,View view,int position,long id)。在此我檢查選定的微調項目是否等於今天。
如果是這樣,我需要更改顯示的列表。
我的問題是無論選擇什麼微調項目,列表都會保持不變。它不會改變。
請注意,我的微調和列表在同一頁上。有人能爲此提出一個解決方案嗎?
public class RecentJobListActivity extends Activity {
ListView listView ;
private Spinner spinner;
private TakenJobDataBaseOpenHelper jobDatabaseHelper;
private Cursor cursor;
SimpleCursorAdapter cursoradapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recent_job_list);
addItemsOnSpinner();
//This is the database helper class
jobDatabaseHelper = new TakenJobDataBaseOpenHelper(this);
String[] fromColumns = {TakenJobDataBaseOpenHelper.TAKENJOBS_COLUMN_RequestID,TakenJobDataBaseOpenHelper.TAKENJOBS_COLUMN_Destination,TakenJobDataBaseOpenHelper.TAKENJOBS_COLUMN_CustomerName};
int[] toViews = {R.id.singleRequestID, R.id.singleDestination,R.id.singleCustomerName};
//when the page first loads the result of queru getAlljobs() will be shown.this works
cursor = jobDatabaseHelper.getAllJobs();
cursoradapter = new SimpleCursorAdapter(this,
R.layout.single_job_activity, cursor, fromColumns, toViews, 0);
listView = (ListView)findViewById(R.id.activities_list);
listView.setAdapter(cursoradapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.recent_job_list, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void addItemsOnSpinner(){
spinner = (Spinner) findViewById(R.id.time_periods_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.time_periods_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String s = parent.getItemAtPosition(position).toString();
//even the log doesn't show.
if(s.equals("Today")){
Log.d("today","today");
cursor = jobDatabaseHelper.getTodayJobs();
cursoradapter.notifyDataSetChanged();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
謝謝!
如果日誌沒有顯示,那麼它不會進入'if'條件。你確定價值是'今天'嗎?請記住它是'區分大小寫' – Aniruddha
訪問http://stackoverflow.com/questions/19833100/android-updating-list-view-on-spinner-selection – Alpesh