Example usage for android.widget TableRow setLongClickable

List of usage examples for android.widget TableRow setLongClickable

Introduction

In this page you can find the example usage for android.widget TableRow setLongClickable.

Prototype

public void setLongClickable(boolean longClickable) 

Source Link

Document

Enables or disables long click events for this view.

Usage

From source file:se.frikod.payday.DailyBudgetFragment.java

private void updateBudgetItems() {

    TableLayout itemsTable = (TableLayout) V.findViewById(R.id.budgetItems);
    itemsTable.removeAllViews();//from   w  ww  .j a  va2 s.c  o m

    for (int i = 0; i < budget.budgetItems.size(); i++) {
        BudgetItem bi = budget.budgetItems.get(i);
        final int currentIndex = i;
        LayoutInflater inflater = activity.getLayoutInflater();
        TableRow budgetItemView = (TableRow) inflater.inflate(R.layout.daily_budget_budget_item, itemsTable,
                false);

        TextView amount = (TextView) budgetItemView.findViewById(R.id.budgetItemAmount);
        TextView title = (TextView) budgetItemView.findViewById(R.id.budgetItemLabel);

        amount.setText(budget.formatter.format(bi.amount));

        title.setText(bi.title);

        if (bi.exclude) {
            amount.setTextColor(0xffCCCCCC);
            amount.setPaintFlags(amount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

            title.setTextColor(0xffCCCCCC);
            title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        }

        budgetItemView.setClickable(true);
        budgetItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
                vibrator.vibrate(10);

                BudgetItem bi = budget.budgetItems.get(currentIndex);
                bi.exclude = !bi.exclude;
                budget.saveBudgetItems();
                updateBudgetItems();
            }
        });

        budgetItemView.setLongClickable(true);
        budgetItemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                editBudgetItem(v, currentIndex);
                return true;
            }
        });
        itemsTable.addView(budgetItemView);
    }

    FontUtils.setRobotoFont(activity, itemsTable);
    updateBudget();
}