コード例 #1
0
 public void run() {
   adapter.applySortMethod();
   adapter.notifyDataSetChanged();
   spinAdapter.notifyDataSetChanged();
 }
コード例 #2
0
  /**
   * onStart method Setup the adapter for the user's question list, and setup listener for each item
   * (question) in the user's question list.
   */
  @Override
  public void onStart() {
    super.onStart();
    cacheController = new CacheController(mcontext);
    authorMapController = new AuthorMapController(mcontext);
    authorMapManager = new AuthorMapManager();
    myQuestionListController = new QuestionListController();
    myQuestionListManager = new QuestionListManager();
    adapter =
        new QuestionListAdapter(
            mcontext, R.layout.single_question, myQuestionListController.getQuestionArrayList());
    adapter.setSortingOption(sortByDate);
    spinAdapter = new ArrayAdapter<String>(mcontext, R.layout.spinner_item, sortOption);
    mListView.setAdapter(adapter);
    sortOptionSpinner.setAdapter(spinAdapter);
    sortOptionSpinner.setOnItemSelectedListener(new change_category_click());
    updateList();
    /**
     * Jump to the layout of the choosen question, and show details when click on an item (a
     * question) in the favorite question list
     */
    mListView.setOnItemClickListener(
        new OnItemClickListener() {
          /**
           * display the layout of the chosen question, and show details when click on an item (a
           * question) in the searching result list
           *
           * @param parent The adapter of the item in the list.
           * @param view The view.
           * @param pos The position of a question.
           * @param id The ID of a question.
           */
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            long questionID = myQuestionListController.getQuestion(pos - 1).getID();
            Intent intent = new Intent(mcontext, QuestionDetailActivity.class);
            intent.putExtra(QuestionDetailActivity.QUESTION_ID, questionID);
            intent.putExtra(QuestionDetailActivity.CACHE_LIST, cacheList);
            startActivity(intent);
          }
        });

    /** Delete an item (a question) in the favorite list when a user long clicks the question. */
    mListView.setOnItemLongClickListener(
        new OnItemLongClickListener() {
          /**
           * If the user is the author of the question, and the user long click the item (the
           * question) in the question list, then remove the selected question from the question
           * list.
           *
           * @param parent The adapter of the item in the list.
           * @param view The view.
           * @param pos The position of a question.
           * @param id The ID of a question.
           */
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Question question = myQuestionListController.getQuestion(position - 1);
            if (User.author != null && User.author.getUserId() == question.getUserId()) {
              Toast.makeText(
                      mcontext, "Deleting the Question: " + question.getTitle(), Toast.LENGTH_LONG)
                  .show();
              Thread thread = new DeleteThread(question.getID());
              thread.start();
            } else {
              Toast.makeText(mcontext, "Only Author to the Question can delete", Toast.LENGTH_LONG)
                  .show();
            }
            return true;
          }
        });
    /** Update the current questions on screen, if a user scroll his/her favorite question list */
    mListView.setScrollListViewListener(
        new IXListViewListener() {
          /**
           * Will called to update the content in the favorite question list when the data is
           * changed or sorted; also, this method will tell the user the current interval of the
           * question that are displayed on the screen
           */
          @Override
          public void onRefresh() {
            mHandler.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    adapter.notifyDataSetChanged();
                    onLoad();
                  }
                },
                2000);
          }

          /**
           * this method will be called when a user up or down scroll the favorite question list to
           * update the corresponding questions on the screen; also, this method will tell the user
           * the current interval of the question that are displayed on the screen
           */
          @Override
          public void onLoadMore() {
            mHandler.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    adapter.notifyDataSetChanged();
                    onLoad();
                  }
                },
                2000);
          }
        });
  }