コード例 #1
0
 private void addCategory() {
   String name = mNewCategoryText.getText().toString();
   Category category = new Category(name);
   category.save();
   mCategories.add(name);
   mAdapter.notifyDataSetChanged();
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNewCategoryButton = (Button) findViewById(R.id.newTaskButton);
    mNewCategoryText = (EditText) findViewById(R.id.newTask);

    mCategories = new ArrayList<String>();
    for (Category category : Category.all()) {
      mCategories.add(category.getName());
      Log.d(TAG, category.getId().toString());
    }

    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mCategories);
    setListAdapter(mAdapter);

    mNewCategoryButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            addCategory();
          }
        });
  }