簡體   English   中英

選擇微調器項目時,列表不會更改

[英]when a spinner item is selected the List doesn't change

我有一個活動,其中有一個微調器用於選擇一天,以及一個列表,該列表應根據從微調器中選擇的項目顯示列表項。

我正在查詢sqlite數據庫,並且必須對微調器上選擇的不同項目使用不同的查詢。

我正在使用一個簡單的游標適配器。

我已經為微調器設置了onItemSelected(AdapterView<?>父級,View視圖,int位置,長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

            }
        });


    }

}

謝謝!!!

嘗試使用CursorAdapter.swapCursor()。 那應該工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM