Example usage for android.widget TableLayout indexOfChild

List of usage examples for android.widget TableLayout indexOfChild

Introduction

In this page you can find the example usage for android.widget TableLayout indexOfChild.

Prototype

public int indexOfChild(View child) 

Source Link

Document

Returns the position in the group of the specified child view.

Usage

From source file:de.tobiasbielefeld.solitaire.ui.manual.ManualGames.java

@Override
public void onClick(View v) {
    //get index of the button as seen from the container
    TableRow row = (TableRow) v.getParent();
    TableLayout table = (TableLayout) row.getParent();
    int index = table.indexOfChild(row) * COLUMNS + row.indexOfChild(v);

    loadGameText(index);//  ww w.j a  v a2 s .co m
}

From source file:org.mifos.androidclient.main.DepositDueDetailsActivity.java

private void updateContent(SavingsAccountDepositDue details) {
    mDetails = details;/* www .ja v a2s .co m*/
    TextView cell;
    Double nextDeposit, pastDepositAmount, pastDepositsSum = 0.0;

    cell = (TextView) findViewById(R.id.depositDueDetails_nextDeposit);
    nextDeposit = details.getNextDueDetail().getDueAmount();
    cell.setText(nextDeposit.toString());

    if (ValueUtils.hasElements(details.getPreviousDueDetails())) {
        TableLayout table = (TableLayout) findViewById(R.id.depositDueDetails_table);
        View view = findViewById(R.id.depositDueDetails_rowInsertPoint);
        int index = table.indexOfChild(view) + 1;
        view = findViewById(R.id.depositDueDetails_subTotal_label);
        TableLayoutHelper helper = new TableLayoutHelper(this,
                TableLayoutHelper.DEFAULT_TABLE_ROW_SEPARATOR_HEIGHT, view.getPaddingLeft(),
                view.getPaddingRight());

        for (DueOnDate pastDeposit : details.getPreviousDueDetails()) {
            if (pastDeposit.getDueDate().before(details.getNextDueDetail().getDueDate())) {
                TableRow row = helper.createTableRow();
                cell = helper.createTableCell(DateUtils.format(pastDeposit.getDueDate()), 1);
                row.addView(cell);
                pastDepositAmount = pastDeposit.getDueAmount();
                cell = helper.createTableCell(pastDepositAmount.toString(), 2);
                row.addView(cell);
                table.addView(row, index);
                index++;
                table.addView(helper.createRowSeparator(), index);
                index++;
                pastDepositsSum += pastDepositAmount;
            }
        }
    }

    cell = (TextView) findViewById(R.id.depositDueDetails_subTotal);
    cell.setText(pastDepositsSum.toString());
    cell = (TextView) findViewById(R.id.depositDueDetails_totalAmountDue_label);
    cell.setText(cell.getText() + DateUtils.format(details.getNextDueDetail().getDueDate()));
    cell = (TextView) findViewById(R.id.depositDueDetails_totalAmountDue);
    cell.setText(Double.toString(pastDepositsSum + nextDeposit));
}

From source file:de.grobox.liberario.TripsActivity.java

private void addTrips(final TableLayout main, List<Trip> trip_list, boolean append) {
    if (trip_list != null) {
        // reverse order of trips if they should be prepended
        if (!append) {
            ArrayList<Trip> tempResults = new ArrayList<Trip>(trip_list);
            Collections.reverse(tempResults);
            trip_list = tempResults;/*  w  w  w . j av  a2s .  c o m*/
        }

        for (final Trip trip : trip_list) {
            final LinearLayout trip_layout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.trip,
                    null);
            TableRow row = (TableRow) trip_layout.findViewById(R.id.tripTableRow);

            // Locations
            TextView fromView = (TextView) row.findViewById(R.id.fromView);
            fromView.setText(trip.from.uniqueShortName());
            TextView toView = ((TextView) row.findViewById(R.id.toView));
            toView.setText(trip.to.uniqueShortName());

            // Departure Time and Delay
            TextView departureTimeView = (TextView) row.findViewById(R.id.departureTimeView);
            TextView departureDelayView = (TextView) row.findViewById(R.id.departureDelayView);
            if (trip.getFirstPublicLeg() != null) {
                LiberarioUtils.setDepartureTimes(this, departureTimeView, departureDelayView,
                        trip.getFirstPublicLeg().departureStop);
            } else {
                departureTimeView.setText(DateUtils.getTime(this, trip.getFirstDepartureTime()));
            }

            // Arrival Time and Delay
            TextView arrivalTimeView = (TextView) row.findViewById(R.id.arrivalTimeView);
            TextView arrivalDelayView = (TextView) row.findViewById(R.id.arrivalDelayView);
            if (trip.getLastPublicLeg() != null) {
                LiberarioUtils.setArrivalTimes(this, arrivalTimeView, arrivalDelayView,
                        trip.getLastPublicLeg().arrivalStop);
            } else {
                arrivalTimeView.setText(DateUtils.getTime(this, trip.getLastArrivalTime()));
            }

            // Duration
            TextView durationView = (TextView) trip_layout.findViewById(R.id.durationView);
            durationView
                    .setText(DateUtils.getDuration(trip.getFirstDepartureTime(), trip.getLastArrivalTime()));

            // Transports
            FlowLayout lineLayout = (FlowLayout) trip_layout.findViewById(R.id.lineLayout);

            // for each leg
            for (final Leg leg : trip.legs) {
                if (leg instanceof Trip.Public) {
                    LiberarioUtils.addLineBox(this, lineLayout, ((Public) leg).line);
                } else if (leg instanceof Trip.Individual) {
                    LiberarioUtils.addWalkingBox(this, lineLayout);
                }
            }

            // remember trip in view for onClick event
            trip_layout.setTag(trip);

            // make trip details fold out and in on click
            trip_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    View v = main.getChildAt(main.indexOfChild(view) + 1);

                    if (v != null) {
                        if (v.getVisibility() == View.GONE) {
                            v.setVisibility(View.VISIBLE);
                        } else if (v.getVisibility() == View.VISIBLE) {
                            v.setVisibility(View.GONE);
                        }
                    }
                }

            });
            trip_layout.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    selectTrip(view, trip_layout);
                    return true;
                }
            });

            // show more button for trip details
            final ImageView showMoreView = (ImageView) trip_layout.findViewById(R.id.showMoreView);
            showMoreView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    selectTrip(view, trip_layout);
                }
            });

            // Create container for trip details fragment
            FrameLayout fragmentContainer = new FrameLayout(this);
            fragmentContainer.setId(mContainerId);
            fragmentContainer.setVisibility(View.GONE);

            // Create a new Fragment to be placed in the activity layout
            TripDetailFragment tripDetailFragment = new TripDetailFragment();

            // In case this activity was started with special instructions from an
            // Intent, pass the Intent's extras to the fragment as arguments
            Bundle bundle = new Bundle();
            bundle.putSerializable("de.schildbach.pte.dto.Trip", trip);
            bundle.putSerializable("de.schildbach.pte.dto.Trip.from", from);
            bundle.putSerializable("de.schildbach.pte.dto.Trip.to", to);
            tripDetailFragment.setArguments(bundle);

            // Add the fragment to the 'fragment_container' FrameLayout
            getSupportFragmentManager().beginTransaction().add(mContainerId, tripDetailFragment).commit();

            mContainerId++;

            if (append) {
                trip_layout.addView(LiberarioUtils.getDivider(this));
                main.addView(trip_layout);
                main.addView(fragmentContainer);
            } else {
                trip_layout.addView(LiberarioUtils.getDivider(this), 0);
                main.addView(trip_layout, 0);
                main.addView(fragmentContainer, 1);
            }
        } // end foreach trip

    } else {
        // TODO offer option to query again for trips
    }
}