示例#1
0
  private void showWordList() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String orderPreferenceKey = getString(R.string.pref_order_key);
    String order = prefs.getString(orderPreferenceKey, DbHandler.KEY_DATE_MS + " DESC");

    Cursor cursorWords = dbHandler.fetchAllWords(order);
    startManagingCursor(cursorWords);

    List<WordAdapter> words = new ArrayList<WordAdapter>();

    if (cursorWords.moveToFirst()) {
      // Recorremos el cursor hasta que no haya más registros
      do {
        String name = cursorWords.getString(0);
        String date = cursorWords.getString(1);
        float rating = cursorWords.getFloat(2);
        int comments = cursorWords.getInt(3);
        WordAdapter word = new WordAdapter();
        word.setWord(name);
        word.setDate(date);
        word.setRating(rating);
        word.setComments(comments);
        words.add(word);
      } while (cursorWords.moveToNext());
    }

    adapter = new WordListAdapter(this, R.layout.listpresentation, words);

    setListAdapter(adapter);
  }
示例#2
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   if (dbHandler != null) {
     dbHandler.close();
   }
   filterText.removeTextChangedListener(filterTextWatcher);
 }
示例#3
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ctx = this;

    setContentView(R.layout.mainlist);

    registerForContextMenu(getListView());

    dbHandler = new DbHandler(ctx);
    dbHandler.open();

    if (dbHandler.getTodayWord().equals("")) {
      dialog = new ProgressDialog(ctx);
      dialog.setMessage("Descargando nuevas palabras...");
      dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
      dialog.setCancelable(false);
      new DownloadWords().execute();
    } else {
      showWordList();
    }

    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    new DownloadNumberOfComments().execute();

    searchButton = (ImageButton) findViewById(R.id.imageButtonSearch);
    searchButton.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            searchButton.setVisibility(ImageButton.GONE);
            filterText.setVisibility(EditText.VISIBLE);
          }
        });

    filterText = (EditText) findViewById(R.id.editTextSearch);
    filterText.addTextChangedListener(filterTextWatcher);
  }