Example usage for android.widget Button Button

List of usage examples for android.widget Button Button

Introduction

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

Prototype

public Button(Context context) 

Source Link

Document

Simple constructor to use when creating a button from code.

Usage

From source file:org.smap.smapTask.android.activities.TaskAddressActivity.java

/** Called when the activity is first created. */
@Override//  www.  j av  a  2 s  . co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.task_address);

    // Get the id of the selected list item
    Bundle bundle = getIntent().getExtras();

    taskEntry = Utilities.getTaskWithId(bundle.getLong("id"));

    try {

        //String assignment_status = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_STATUS));
        //String taskTitle = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_TITLE));
        //String taskAddress = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_ADDRESS));

        // Formatting
        LinearLayout.LayoutParams textLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        textLayout.setMargins(1, 1, 1, 1);

        TableRow.LayoutParams trLayout = new TableRow.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        trLayout.setMargins(1, 1, 1, 1);

        TableLayout tableLayout = (TableLayout) findViewById(R.id.task_address_values);

        // Add Title
        TextView title = (TextView) findViewById(R.id.task_title);
        title.setText(taskEntry.name);

        // Add Status
        TableRow r = new TableRow(this);
        r.setLayoutParams(trLayout);
        r.setBackgroundColor(0xff0000);
        TextView text1 = new TextView(this);
        text1.setText("Status");
        text1.setBackgroundColor(0xff0000);
        TextView text2 = new TextView(this);
        text2.setText(taskEntry.taskStatus);
        text2.setBackgroundColor(0xff0000);
        r.addView(text1);
        r.addView(text2);
        tableLayout.addView(r);

        // Put the Address items in the table
        Type type = new TypeToken<ArrayList<Address>>() {
        }.getType();
        ArrayList<Address> aArray = new Gson().fromJson(taskEntry.taskAddress, type);
        if (aArray != null) {
            for (int i = 0; i < aArray.size(); i++) {

                r = new TableRow(this);
                r.setLayoutParams(trLayout);
                r.setBackgroundColor(0xff0000);

                text1 = new TextView(this);
                text1.setText(aArray.get(i).name);
                text1.setBackgroundColor(0xff0000);

                text2 = new TextView(this);
                text2.setText(aArray.get(i).value);
                text2.setBackgroundColor(0xff0000);

                r.addView(text1);
                r.addView(text2);
                tableLayout.addView(r);
            }
        }

        // Create the buttons
        LinearLayout buttons = (LinearLayout) findViewById(R.id.task_address_buttons);
        //menu.setHeaderTitle(taskTitle);
        if (Utilities.canReject(taskEntry.taskStatus)) {

            Button b = new Button(this);
            b.setText("Reject Task");
            b.setId(R.id.reject_button);
            b.setOnClickListener(this);
            buttons.addView(b);
        }
        if (Utilities.canComplete(taskEntry.taskStatus)) {
            Button b = new Button(this);
            b.setText("Complete Task");
            b.setId(R.id.complete_button);
            b.setOnClickListener(this);
            buttons.addView(b);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.forgerock.openam.mobile.example.authentication.activities.authenticate.AuthenticateActivity.java

/**
 * Draws the submit button for this authenticate stage.
 *
 * Upon clicking the button, we call the authentication client's authenticate function
 * passing back the now-filled-in json//from  w w w . j a  v  a  2s  . com
 *
 * @param dcs The drawable callbacks
 * @param authCallbackString JSON data returned describing this auth step
 * @return the button object to display
 */
private Button createSubmitButton(final DrawableCallback[] dcs, final String authCallbackString) {

    Button submitButton = new Button(this);
    submitButton.setText("Submit");
    submitButton.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    //for each callback,
    submitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Hashtable<String, String> myVals = new Hashtable<String, String>();

            for (DrawableCallback dc : dcs) {
                myVals.put(dc.getId(), dc.getValue());
            }

            JSONObject jsonToAlter = null;

            try {
                jsonToAlter = new JSONObject(authCallbackString);
                getAuthNClient().replaceAuthenticateInputVals(jsonToAlter, myVals);

            } catch (JSONException e) {
                Log.e(TAG, "Unable to modify JSON representation of authentication stage.", e);
            }

            getAuthNClient().authenticate(jsonToAlter);
        }
    });

    return submitButton;
}

From source file:mobisocial.musubi.ui.fragments.ConversationsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (null != mActivity.findViewById(R.id.feed_view)) {
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }/*from w w w  .  j  a  va 2  s.  c o m*/

    Button startConversation = new Button(getActivity());
    startConversation.setText("New conversation");
    startConversation.setOnClickListener(mNewConversationListener);
    getListView().addHeaderView(startConversation);

    mFeeds = new FeedListAdapter(mActivity);
    mFeeds.setPinnedPartitionHeadersEnabled(false);

    for (int i = 0; i < FeedListFragment.DAYS_TO_SHOW + 1; i++) {
        mFeeds.addPartition(false, true);
    }
    setListAdapter(mFeeds);

    /** Load the latest feeds in the background **/
    initLoaders(false);
    mActivity.findViewById(R.id.start_something).setVisibility(View.GONE);
}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

public void createButtonWithText(Activity activity, ViewGroup l, String text, String button,
        View.OnClickListener onclick) {
    RelativeLayout r = new RelativeLayout(activity);
    r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    TextView tv = new TextView(activity);
    RelativeLayout.LayoutParams tvparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tvparams.addRule(RelativeLayout.ABOVE, R.id.reload_button);
    tvparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    tv.setLayoutParams(tvparams);// ww  w  .j  av a2  s  . c o  m
    tv.setText(text);
    tv.setTextSize(23);
    tv.setPadding(0, 0, 0, toPixels(15));
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    r.addView(tv);

    Button b = new Button(activity);
    RelativeLayout.LayoutParams bparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    bparams.addRule(RelativeLayout.CENTER_VERTICAL);
    bparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    b.setLayoutParams(bparams);
    b.setId(R.id.reload_button);
    b.setText(button);
    b.setTextSize(23);
    b.setAllCaps(false);
    b.setTypeface(null, Typeface.NORMAL);
    b.setOnClickListener(onclick);
    r.addView(b);

    l.addView(r);
}

From source file:foam.starwisp.DrawableMap.java

public void init(int id, ViewGroup parent, StarwispActivity c, StarwispBuilder b, String mode) {
    m_parent = parent;// w  ww  .j a v a  2  s .c  o m
    map_ready = false;
    draw_mode = false;
    button_mode = false;
    m_Context = c;
    m_Builder = b;
    map_mode = mode;
    ID = id;
    current_polygon = new Vector<LatLng>();
    polygons = new Vector<Polygon>();
    centre_lat = 49.198935;
    centre_lon = 2.988281;
    centre_zoom = 4;
    draw_indicator = false;
    indicator_lat = 0;
    indicator_lon = 0;

    FrameLayout outer_map = new FrameLayout(c);
    outer_map.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.FILL_PARENT));

    FrameLayout map_container = new FrameLayout(c);
    map_container.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.FILL_PARENT));

    map_container.setId(ID);
    SupportMapFragment mapfrag = SupportMapFragment.newInstance();
    FragmentTransaction fragmentTransaction = c.getSupportFragmentManager().beginTransaction();
    fragmentTransaction.add(ID, mapfrag);
    fragmentTransaction.commit();
    outer_map.addView(map_container);

    fram_map = new FrameLayout(c);
    fram_map.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.FILL_PARENT));
    outer_map.addView(fram_map);

    if (map_mode.equals("edit")) {
        map_cont = new LinearLayout(c);
        map_cont.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.FILL_PARENT);
        lp.gravity = Gravity.CENTER;
        map_cont.setLayoutParams(lp);

        scribble_button = new Button(c);
        lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER;
        scribble_button.setLayoutParams(lp);

        scribble_button.setTextSize(20);
        scribble_button.setTypeface(((StarwispActivity) c).m_Typeface);
        scribble_button.setText("Draw field");
        map_cont.addView(scribble_button);

        m_instructions = new TextView(c);
        m_instructions.setLayoutParams(lp);
        m_instructions.setTextSize(20);
        m_instructions.setTypeface(m_Context.m_Typeface);
        m_instructions.setTextColor(Color.WHITE);
        // arg i18n
        map_cont.addView(m_instructions);

        fram_map.addView(map_cont);

    } else {
        //button_mode=true;
    }

    parent.addView(outer_map);

    mapfrag.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            map = googleMap;
            map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            map.setMyLocationEnabled(true);
            map.getUiSettings().setZoomControlsEnabled(true);
            SetupStuff();
            DrawMap();
            Log.i("starwisp", "map made");
            Log.i("starwisp", "updating map centre to " + centre_lat + " " + centre_lon);
            //CameraUpdate center_map=CameraUpdateFactory.newLatLng(new LatLng(centre_lat,centre_lon));
            //CameraUpdate zoom_map=CameraUpdateFactory.zoomTo(centre_zoom);
            //map.moveCamera(center_map);
            //map.animateCamera(zoom_map);

            CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(new LatLng(centre_lat, centre_lon)).zoom(centre_zoom).build();
            map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

            map_ready = true;
        }
    });

}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

/**
 * Executed when tabhost is created/*from  ww  w.  j  a  v a2 s  .c  o  m*/
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // ----------------- GUI ------------
    resources = SetResources(); // ---Load Prefs and Modify resources
    // accordingly
    setContentView(R.layout.factivity_tabhost); // ---------- Content view
    ctx = this;

    btSetup = new Button(ctx);

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    btSetup.setLayoutParams(params);

    RelativeLayout rl = (RelativeLayout) findViewById(R.id.tbs);
    rl.addView(btSetup);
    btSetup.bringToFront();

    btSetup.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (Fragment_Issue_Details.mfrag_issue_details != null) {
                FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                ft.remove(Fragment_Issue_Details.mfrag_issue_details);
                ft.commit();
                getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
            }

            mTabHost.getTabWidget().getChildAt(4).findViewWithTag("hbar")
                    .setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_orange));
            startActivity(new Intent(ctx, Activity_Setup.class));
        }
    });

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);

    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

    // ---------------------------------------
    for (int i = 0; i < NTabs; i++)
        mTabSpec[i] = mTabHost.newTabSpec("tid" + Integer.toString(i));

    mD_Main = getResources().getDrawable(R.drawable.ic_map);
    mD_List = getResources().getDrawable(R.drawable.ic_list);
    mD_Report = getResources().getDrawable(R.drawable.ic_plus);
    mD_Filters = getResources().getDrawable(R.drawable.ic_filter);
    mD_Setup = getResources().getDrawable(R.drawable.ic_settings);

    // -------------- Set icons and texts localized per tab -------------
    LinearLayout llA = make_Active_Tab(resources.getString(R.string.Map), mD_Main);
    llA.setClickable(true);
    LinearLayout llB = make_Inactive_Tab(resources.getString(R.string.List), mD_List);
    LinearLayout llC = make_Inactive_Tab(resources.getString(R.string.Report), mD_Report);
    LinearLayout llD = make_Inactive_Tab(resources.getString(R.string.Filter), mD_Filters);
    LinearLayout llE = make_Inactive_Tab(resources.getString(R.string.Settings), mD_Setup);

    mTabSpec[0].setIndicator(llA);
    mTabSpec[1].setIndicator(llB);
    mTabSpec[2].setIndicator(llC);
    mTabSpec[3].setIndicator(llD);
    mTabSpec[4].setIndicator(llE);

    // Add tabSpec to the TabHost to display
    mTabHost.addTab(mTabSpec[0], Fragment_Map.class, null);
    mTabHost.addTab(mTabSpec[1], Fragment_List.class, null);
    mTabHost.addTab(mTabSpec[2], Fragment_NewIssueA.class, null);
    mTabHost.addTab(mTabSpec[3], Fragment_Filters.class, null);
    mTabHost.addTab(mTabSpec[4], null, null); // implemented with a button
    // overlapped because there
    // was no fragment for
    // Preferences in support
    // lib v4

    mTabHost.setOnTabChangedListener(this);

    mTabHost.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            btSetup.setWidth(mTabHost.getTabWidget().getChildAt(4).getWidth());
            btSetup.setHeight(mTabHost.getTabWidget().getChildAt(4).getHeight());
            btSetup.bringToFront();
        }
    });

}

From source file:free.yhc.netmbuddy.YTSearchActivity.java

private void preparePageButtons() {
    mPageBtnHolder = new Button[Policy.YTSEARCH_NR_PAGE_INDEX_BUTTONS];
    mPageBtnLPHolder = new LinearLayout.LayoutParams(
            getResources().getDimensionPixelSize(R.dimen.ytsearch_idxbtn_width),
            getResources().getDimensionPixelSize(R.dimen.ytsearch_idxbtn_height));
    mPageBtnLPHolder.gravity = Gravity.CENTER_VERTICAL;
    for (int i = 0; i < mPageBtnHolder.length; i++) {
        mPageBtnHolder[i] = new Button(this);
        mPageBtnHolder[i].setTag(i);//from   ww w  . ja  v a  2s .  c  o  m
        mPageBtnHolder[i].setOnClickListener(mPageOnClick);
    }
}

From source file:markson.visuals.sitapp.settingActivity.java

@SuppressWarnings("deprecation")
public void addnum(String crn) {
    crns[num] = crn;/*from  www.j a  va  2 s .c om*/
    num++;
    full();
    Button myButton = new Button(this);
    myButton.setText(crn);
    LinearLayout layout = (LinearLayout) findViewById(R.id.crnlayout);
    myButton.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
    myButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            Button b = (Button) v;
            String buttonText = b.getText().toString();
            rembut(buttonText);
            //v.setEnabled(false);
            v.setVisibility(View.GONE);

        }
    });
    layout.addView(myButton);

}

From source file:nl.openkvk.MainActivity.java

private void globalSearchResults(Object obj) {
    {/*from w  w w. j  a va 2  s.  com*/
        Log.d("Result", obj.toString());
        TableLayout tl = (TableLayout) findViewById(R.id.tableOuter);
        tl.removeAllViews();
        JSONResult res = new JSONResult((JSONObject) ((JSONObject) ((JSONArray) obj).get(0)).get("RESULT"));
        if (res.size() < 1) {
            TextView v1 = new TextView(this);
            v1.setText("Niets gevonden voor deze zoekvraag.");
            TableRow tr = new TableRow(this);
            tr.addView(v1);
            tl.addView(tr);
        }
        for (int r = 0; r < res.size(); r++) {
            {
                TableRow tr = new TableRow(this);
                TextView v1 = new TextView(this);
                tr.addView(v1);
                tl.addView(tr);
            }
            print(tl, "Naam: ", res.getValue(r, "bedrijfsnaam"));
            print(tl, "KvK: ", res.getValue(r, "kvks"));
            print(tl, "VestNr: ", res.getValue(r, "vestiging"));
            print(tl, "Type: ", res.getValue(r, "type"));
            print(tl, "Rechtsvorm: ", res.getValue(r, "rechtsvorm"));
            print(tl, "Status: ", res.getValue(r, "status"));
            print(tl, "Website: ", res.getValue(r, "website"));
            print(tl, "ANBI: ", res.getValue(r, "anbi"));
            print(tl, "Adres: ", res.getValue(r, "adres"));
            String po = res.getValue(r, "postcode");
            String pl = res.getValue(r, "plaats");
            if (po != null || pl != null) {
                if (po == null) {
                    print(tl, "", pl);
                } else if (pl == null) {
                    print(tl, "", po);
                } else {
                    print(tl, "", po + " " + pl);
                }
            }
            {
                TableRow tr = new TableRow(this);
                if (res.getValue(r, "kvk") != null && res.getValue(r, "kvks") != null) {
                    Button but = new Button(this);
                    but.setText("Details");
                    but.setTextSize(10);
                    but.setOnClickListener(new KvkButListener(res.getValue(r, "kvk"), res.getValue(r, "kvks")));
                    tr.addView(but);
                } else {
                    tr.addView(new TextView(this));
                }
                tr.addView(new TextView(this));
                if (po != null) {
                    Button but = new Button(this);
                    but.setText("Postcode");
                    but.setTextSize(10);
                    but.setOnClickListener(new PostcodeButListener(po));
                    tr.addView(but);
                }
                tl.addView(tr);
            }
        }
    }
}

From source file:de.uni_weimar.m18.anatomiederstadt.element.QuizMulti.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_quiz_multi, container, false);
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.quizMultiLayout);

    final ArrayList<CheckBox> checkBoxes = new ArrayList<>();
    for (int i = 0; i < mOptions.size(); ++i) {
        CheckBox checkBox = new CheckBox(getActivity());
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(16, 0, 0, 0);
        checkBox.setLayoutParams(layoutParams);
        checkBox.setText(mOptions.get(i));
        linearLayout.addView(checkBox);//from  ww  w .  jav  a  2 s. co m
        checkBoxes.add(checkBox);
    }

    Button button = new Button(getActivity());
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.CENTER;
    button.setLayoutParams(layoutParams);

    button.setText("Eingeben");

    linearLayout.addView(button);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // evaluate score
            int correct = 0;
            int notcorrect = 0;

            for (int i = 0; i < checkBoxes.size(); ++i) {
                if (checkBoxes.get(i).isChecked()) {
                    if (mCorrect.get(i).equals("true")) {
                        correct += 1;
                    } else {
                        notcorrect += 1;
                    }
                } else {
                    if (mCorrect.get(i).equals("false")) {
                        //correct += 1;
                    } else {
                        notcorrect += 1;
                    }
                }
            }

            int totalcorrect = correct - notcorrect;
            if (totalcorrect < 0)
                totalcorrect = 0;
            int score = totalcorrect * mPoints;
            // TODO: submit score
            submitPointsToBackend(score);
            String congratulations = "";
            if (totalcorrect == 2) {
                congratulations = String.format(getString(R.string.congratulations_exact_format_string), score);
            } else if (totalcorrect == 1) {
                congratulations = String.format(getString(R.string.congratulations_not_quite_format_string),
                        score);
            } else {
                congratulations = String.format(getString(R.string.congratulations_wrong_format_string), score);
            }
            SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                    .margin(32, 32).backgroundDrawable(R.drawable.points_snackbar_shape).text(congratulations)
                    .eventListener(new EventListener() {
                        @Override
                        public void onShow(Snackbar snackbar) {

                        }

                        @Override
                        public void onShowByReplace(Snackbar snackbar) {

                        }

                        @Override
                        public void onShown(Snackbar snackbar) {

                        }

                        @Override
                        public void onDismiss(Snackbar snackbar) {

                        }

                        @Override
                        public void onDismissByReplace(Snackbar snackbar) {

                        }

                        @Override
                        public void onDismissed(Snackbar snackbar) {
                            if (mListener != null) {
                                mListener.onMultiClick(mTargetId);
                            }
                        }
                    }));

        }
    });

    return view;
}