create TableRow - Android User Interface

Android examples for User Interface:TableRow

Description

create TableRow

Demo Code


import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Calendar;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class Main{
    public static final int DARK_GRAY = Color.rgb(51, 51, 51);
    public static int HIGHLIGHT_COLOR = BLUE;
    /**//from w  w w . jav a2  s.com
     * @fn public static TableRow createTableRow(Context context)
     * Creates a table row with no margins and no padding that will expand to the entire length of the parent TableLayout.
     * @param context
     * @return Created TableRow.
     */
    public static TableRow createTableRow(final Context context) {
        TableRow tableRow = new TableRow(context);
        ///http://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically
        TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
                TableRow.LayoutParams.MATCH_PARENT,
                TableRow.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(2, 2, 2, 2);
        tableRow.setLayoutParams(layoutParams);
        tableRow.setFocusable(true);
        tableRow.setClickable(true);
        tableRow.requestDisallowInterceptTouchEvent(false);
        //tableRow.setBackgroundColor(DARK_GRAY);

        tableRow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                // get the table Row
                //TableRow tr = (TableRow)v;
                // get the table layout above

                ViewGroup tl = (ViewGroup) v.getParent();

                for (int index = 0; index < tl.getChildCount(); index++) {
                    // unselect all children
                    View unselected = tl.getChildAt(index);
                    unselected.setSelected(false);
                    unselected.setBackgroundColor(DARK_GRAY);
                }

                //displayToast(context,"Table row "+v.getId()+"clicked");
                v.setBackgroundColor(HIGHLIGHT_COLOR);
                v.setSelected(true);

            }
        });

        return tableRow;

    }
}

Related Tutorials