private void setCategoryType(Category category) {
   if (category.getParentId() > 0) {
     category.copyTypeFromParent();
   } else {
     if (incomeExpenseButton.isChecked()) {
       category.makeThisCategoryIncome();
     } else {
       category.makeThisCategoryExpense();
     }
   }
 }
 private void updateIncomeExpenseType() {
   if (category.getParentId() > 0) {
     if (category.parent.isIncome()) {
       incomeExpenseButton.setChecked(true);
     } else {
       incomeExpenseButton.setChecked(false);
     }
     incomeExpenseButton.setEnabled(false);
   } else {
     incomeExpenseButton.setChecked(category.isIncome());
     incomeExpenseButton.setEnabled(true);
   }
 }
 private void selectParentCategory(long parentId) {
   Category c = em.getCategory(parentId);
   if (c != null) {
     category.parent = c;
     parentCategoryText.setText(c.title);
   }
   updateIncomeExpenseType();
 }
 private void writeCategory(QifBufferedWriter qifWriter, Category c) throws IOException {
   QifCategory qifCategory = QifCategory.fromCategory(c);
   qifCategory.writeTo(qifWriter);
   if (c.hasChildren()) {
     for (Category child : c.children) {
       writeCategory(qifWriter, child);
     }
   }
 }
 private void addParentAttributes() {
   long categoryId = category.getParentId();
   ArrayList<Attribute> attributes = db.getAllAttributesForCategory(categoryId);
   if (attributes.size() > 0) {
     for (Attribute a : attributes) {
       View v =
           x.inflater.new Builder(parentAttributesLayout, R.layout.select_entry_simple).create();
       v.setTag(a);
       setAttributeData(v, a);
     }
   } else {
     x.addInfoNodeSingle(parentAttributesLayout, -1, R.string.no_attributes);
   }
 }
 @Override
 protected void onClick(View v, int id) {
   switch (id) {
     case R.id.category:
       x.select(
           this,
           R.id.category,
           R.string.parent,
           categoryCursor,
           categoryAdapter,
           CategoryColumns._id.name(),
           category.getParentId());
       break;
     case R.id.new_attribute:
       x.select(
           this,
           R.id.new_attribute,
           R.string.attribute,
           attributeCursor,
           attributeAdapter,
           AttributeColumns.ID,
           -1);
       break;
     case R.id.add_attribute:
       {
         Intent intent = new Intent(this, AttributeActivity.class);
         startActivityForResult(intent, NEW_ATTRIBUTE_REQUEST);
       }
       break;
     case R.id.edit_attribute:
       {
         Object o = v.getTag();
         if (o instanceof Attribute) {
           Intent intent = new Intent(this, AttributeActivity.class);
           intent.putExtra(AttributeColumns.ID, ((Attribute) o).id);
           startActivityForResult(intent, EDIT_ATTRIBUTE_REQUEST);
         }
       }
       break;
     case R.id.remove_attribute:
       attributesLayout.removeView((View) v.getTag());
       attributesLayout.removeView((View) v.getParent());
       scrollView.fullScroll(ScrollView.FOCUS_DOWN);
       break;
   }
 }
 private void editCategory() {
   selectParentCategory(category.getParentId());
   categoryTitle.setText(category.title);
 }