private void setCategoryInfo(FileCategory fc, long count, long size) {
   CategoryInfo info = mCategoryInfo.get(fc);
   if (info == null) {
     info = new CategoryInfo();
     mCategoryInfo.put(fc, info);
   }
   info.count = count;
   info.size = size;
 }
예제 #2
0
  @Override
  public void onItemClick(AdapterView<?> view, View list_textview, int position, long id) {

    final TextView textview = (TextView) view.findViewById(R.id.textview_categoryItem);
    // final TextView textview = (TextView)list_textview;
    final int pos = position;
    final CategoryInfo caterogyIf = (CategoryInfo) view.getItemAtPosition(position);
    final ArrayAdapter<CategoryInfo> adapter = arrayAdapter;

    // アラートダイアログを設定します
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle("編集");
    // alertDialogBuilder.setMessage(textview.getText().toString());

    edittext = new EditText(this);
    edittext.setText(caterogyIf.getCategory());
    alertDialogBuilder.setView(edittext);

    // id = caterogyIf.getId();

    // アラートダイアログの肯定ボタンがクリックされた時に呼び出されるコールバックリスナーを登録します
    alertDialogBuilder.setPositiveButton(
        "更新",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {

            TaskTimeDatabaseHelper dbHelper = new TaskTimeDatabaseHelper(getBaseContext());
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            CategoryEditDao dao = new CategoryEditDao(db);

            // View h = getResources()
            // TextView tvid = (TextView) getParent().findViewById(R.id.textview_categoryId);
            CategoryInfo categoryInfo = new CategoryInfo();
            categoryInfo.setId(caterogyIf.getId());
            categoryInfo.setCategory(edittext.getText().toString());

            int result = dao.update(categoryInfo);
            db.close();

            textview.setText(categoryInfo.getCategory());
            adapter.notifyDataSetChanged();

            // finish();
            // startActivity(getIntent());
          }
        });
    // アラートダイアログの肯定ボタンがクリックされた時に呼び出されるコールバックリスナーを登録します
    alertDialogBuilder.setNeutralButton(
        "削除",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {

            TaskTimeDatabaseHelper dbHelper = new TaskTimeDatabaseHelper(getBaseContext());
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            CategoryEditDao dao = new CategoryEditDao(db);

            int result = dao.delete(caterogyIf.getId());
            db.close();

            adapter.remove(caterogyIf);

            // finish();
            // startActivity(getIntent());
          }
        });

    // アラートダイアログの否定ボタンがクリックされた時に呼び出されるコールバックリスナーを登録します
    alertDialogBuilder.setNegativeButton(
        "戻る",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {}
        });
    // アラートダイアログのキャンセルが可能かどうかを設定します
    alertDialogBuilder.setCancelable(true);
    AlertDialog alertDialog = alertDialogBuilder.create();
    // アラートダイアログを表示します
    alertDialog.show();
  }