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:de.tobiasbielefeld.solitaire.ui.manual.ManualGames.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_manual_games, container, false);

    ((Manual) getActivity()).setGamePageShown(false);

    layout1 = (ScrollView) view.findViewById(R.id.manual_games_layout_selection);
    scrollView = (ScrollView) view.findViewById(R.id.manual_games_scrollView);
    textName = (TextView) view.findViewById(R.id.manual_games_name);
    textStructure = (TextView) view.findViewById(R.id.manual_games_structure);
    textObjective = (TextView) view.findViewById(R.id.manual_games_objective);
    textRules = (TextView) view.findViewById(R.id.manual_games_rules);
    textScoring = (TextView) view.findViewById(R.id.manual_games_scoring);
    textBonus = (TextView) view.findViewById(R.id.manual_games_bonus);

    layout1.setVisibility(View.VISIBLE);
    scrollView.setVisibility(View.GONE);

    //if the manual is called from the in game menu, show the corresponding game rule page
    if (getArguments() != null && getArguments().containsKey(GAME)) {
        loadGameText(getArguments().getString(GAME));
    }/*from   ww w.j a  v  a 2 s.  co m*/

    //load the table
    String[] gameList = lg.getDefaultGameNameList(getResources());
    TableRow row = new TableRow(getContext());
    TableLayout tableLayout = (TableLayout) view.findViewById(R.id.manual_games_container);
    TypedValue typedValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);

    TableRow.LayoutParams params = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT);
    params.weight = 1;

    //add each button
    for (int i = 0; i < lg.getGameCount(); i++) {
        Button entry = new Button(getContext());

        if (i % COLUMNS == 0) {
            row = new TableRow(getContext());
            tableLayout.addView(row);
        }

        entry.setBackgroundResource(typedValue.resourceId);
        entry.setEllipsize(TextUtils.TruncateAt.END);
        entry.setMaxLines(1);
        entry.setLayoutParams(params);
        entry.setText(gameList[i]);
        entry.setOnClickListener(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            entry.setAllCaps(false);
        }

        row.addView(entry);
    }

    //add some dummies to the last row, if necessary
    while (row.getChildCount() < COLUMNS) {
        FrameLayout dummy = new FrameLayout(getContext());
        dummy.setLayoutParams(params);
        row.addView(dummy);
    }

    return view;
}

From source file:com.matthewtamlin.sliding_intro_screen_manual_testing.TestPageLock.java

/**
 * @return creates a Button which navigates to the first page
 *//*w ww  .j  a  v a  2 s  .  c  o  m*/
private Button createGoToFirstPageButton() {
    final Button button = new Button(this);
    button.setText("Go to first page");

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final int startIndex = getIndexOfCurrentPage();
            goToFirstPage();
            validateCommandPageChange(startIndex, 0);
        }
    });

    return button;
}

From source file:co.ldln.android.ObjectCreateFragment.java

@Override
public void onReadSchemaResult(final Schema schema) {
    mTextFields = new ArrayList<EditText>();

    // Create the form based on the schema fields
    List<SchemaField> fieldList = new ArrayList<SchemaField>();
    fieldList.addAll(schema.getFields(mActivity));
    Collections.sort(fieldList);//from  w  ww . ja  v  a2 s.c  o  m
    for (SchemaField field : fieldList) {
        String type = field.getType();
        String label = field.getLabel();

        // Create a linear layout to hold the field
        LinearLayout ll = new LinearLayout(mActivity);
        LayoutParams llParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        ll.setLayoutParams(llParams);
        ll.setOrientation(LinearLayout.HORIZONTAL);

        // TODO: different UI for different field types

        // Default to EditText
        EditText et = new EditText(mActivity);
        LayoutParams etParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        et.setLayoutParams(etParams);
        et.setHint(label);
        if (type.equals("map_location"))
            et.setText(mMapLocation);
        ll.addView(et);
        mTextFields.add(et);

        mFormHolder.addView(ll);
    }

    // Add submit button
    Button b = new Button(mActivity);
    LayoutParams bParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    b.setText("Save");
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                String kvPairs = "";
                JSONObject kvPairsJsonObject = new JSONObject();
                for (EditText et : mTextFields) {
                    String key = et.getHint().toString();
                    String value = et.getText().toString();
                    kvPairsJsonObject.put(key, value);
                }
                kvPairs = kvPairsJsonObject.toString();

                LDLN.saveSyncableObject(mActivity, ObjectCreateFragment.this, schema.getKey(), kvPairs);
            } catch (JSONException e) {
                e.printStackTrace();
                onSaveSyncableObjectResult(false);
            }
        }
    });
    mFormHolder.addView(b);

    Toast.makeText(mActivity,
            "This is a form that's dynamically generated from a syncable object schema. It will soon have handling for dynamic form elements (photo, latlon picker, etc).",
            Toast.LENGTH_LONG).show();
}

From source file:com.arcusapp.soundbox.fragment.SongsListFragment.java

private void addRandomButton() {
    // create the button
    Button myButton = new Button(getActivity());
    myButton.setId(19);//from www . j  av a 2s  .  c om
    myButton.setText(this.getString(R.string.LabelPlaySongsRandom));
    myButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
    myButton.setCompoundDrawablesWithIntrinsicBounds(null, null,
            getResources().getDrawable(R.drawable.icon_random_shuffled), null);
    myButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //start the playActivity
            Intent playActivityIntent = new Intent();
            playActivityIntent.setAction(SoundBoxApplication.ACTION_MAIN_ACTIVITY);
            playActivityIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            getActivity().startActivity(playActivityIntent);

            //call the service to play new songs
            Intent serviceIntent = new Intent(MediaPlayerService.PLAY_NEW_SONGS, null,
                    SoundBoxApplication.getContext(), MediaPlayerService.class);

            Bundle b = new Bundle();
            Collections.shuffle(songsIDs);
            b.putStringArrayList(BundleExtra.SONGS_ID_LIST, new ArrayList<String>(songsIDs));
            b.putString(BundleExtra.CURRENT_ID, BundleExtra.DefaultValues.DEFAULT_ID);

            serviceIntent.putExtras(b);
            getActivity().startService(serviceIntent);
        }
    });

    // add the button to the header of the list
    myListView.addHeaderView(myButton);
}

From source file:com.jdom.word.playdough.android.GamePackPlayerActivity.java

public void updateSourceLetters(List<ButtonConfiguration> buttons) {
    TableLayout availableLettersTable = (TableLayout) findViewById(R.id.source_letters_table);
    availableLettersTable.removeAllViews();
    TableRow row = new TableRow(this);

    for (int i = 0; i < buttons.size(); i++) {
        final ButtonConfiguration buttonConfiguration = buttons.get(i);
        final String displayText = buttonConfiguration.getDisplayText();
        final boolean shouldBeEnabled = buttonConfiguration.isEnabled();
        final Runnable clickAction = buttonConfiguration.getClickAction();

        if (i == 9 || i == 18) {
            availableLettersTable.addView(row);
            row = new TableRow(this);
        }//from   w ww  . j a  v a 2s . c  o  m

        final Button button = new Button(this);
        button.setText(displayText);
        button.setClickable(shouldBeEnabled);
        button.setEnabled(shouldBeEnabled);
        button.setBackgroundColor(Color.BLACK);
        button.setTextSize(20);
        int color = (shouldBeEnabled) ? Color.WHITE : Color.BLACK;
        button.setTextColor(color);

        if (clickAction != null) {
            button.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    clickAction.run();
                }
            });
        }

        row.addView(button);
    }
    availableLettersTable.addView(row);

}

From source file:net.pocketmagic.android.eventinjector.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(LT, "App created.");
    Events.intEnableDebug(1);//w  ww.  j av a  2  s  . c o  m
    // disable the titlebar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // create a basic user interface
    LinearLayout panel = new LinearLayout(this);
    panel.setOrientation(LinearLayout.VERTICAL);
    setContentView(panel);

    EditText v = new EditText(this);
    v.setId(idTextView);
    v.setOnClickListener(this);
    panel.addView(v);

    // --
    Button b = new Button(this);
    b.setText("Scan Input Devs");
    b.setId(idButScan);
    b.setOnClickListener(this);
    panel.addView(b);

    // put list in a scroll view
    LinearLayout listLayout = new LinearLayout(this);
    listLayout.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    m_lvDevices = new ListView(this);
    LayoutParams lvLayoutParam = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    m_lvDevices.setLayoutParams(lvLayoutParam);
    m_lvDevices.setId(idLVDevices);
    m_lvDevices.setDividerHeight(0);
    m_lvDevices.setFadingEdgeLength(0);
    m_lvDevices.setCacheColorHint(0);
    m_lvDevices.setAdapter(null);

    listLayout.addView(m_lvDevices);
    panel.addView(listLayout);
    // --
    LinearLayout panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    m_selDevSpinner = new Spinner(this);
    m_selDevSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    m_selDevSpinner.setId(idSelSpin);
    m_selDevSpinner.setOnItemSelectedListener((OnItemSelectedListener) this);
    panelH.addView(m_selDevSpinner);
    // -- simulate key event
    b = new Button(this);
    b.setText(">Key");
    b.setId(idButInjectKey);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate touch event
    b = new Button(this);
    b.setText(">Tch");
    b.setId(idButInjectTouch);
    b.setOnClickListener(this);
    panelH.addView(b);
    // --
    m_tvMonitor = new TextView(this);
    m_tvMonitor.setText("Event Monitor stopped.");
    panel.addView(m_tvMonitor);
    // --
    panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    b = new Button(this);
    b.setText("Monitor Start");
    b.setId(idButMonitorStart);
    b.setOnClickListener(this);
    panelH.addView(b);
    // --
    b = new Button(this);
    b.setText("Monitor Stop");
    b.setId(idButMonitorStop);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate test event
    b = new Button(this);
    b.setText(">Test");
    b.setId(idButTest);
    b.setOnClickListener(this);
    panelH.addView(b);
}

From source file:com.ichi2.anki.multimediacard.fields.BasicImageFieldController.java

@Override
public void createUI(Context context, LinearLayout layout) {
    mImagePreview = new ImageView(mActivity);

    DisplayMetrics metrics = getDisplayMetrics();

    int height = metrics.heightPixels;
    int width = metrics.widthPixels;

    LinearLayout.LayoutParams p = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    setPreviewImage(mField.getImagePath(), getMaxImageSize());
    mImagePreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    mImagePreview.setAdjustViewBounds(true);

    mImagePreview.setMaxHeight((int) Math.round(height * 0.4));
    mImagePreview.setMaxWidth((int) Math.round(width * 0.6));

    mBtnGallery = new Button(mActivity);
    mBtnGallery.setText(gtxt(R.string.multimedia_editor_image_field_editing_galery));
    mBtnGallery.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww  w. j a va2s.co m*/
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            mActivity.startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
        }
    });

    mBtnCamera = new Button(mActivity);
    mBtnCamera.setText(gtxt(R.string.multimedia_editor_image_field_editing_photo));
    mBtnCamera.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            File image;
            File storageDir;
            String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(new Date());
            try {
                storageDir = mActivity.getCacheDir();
                image = File.createTempFile("img_" + timeStamp, ".jpg", storageDir);
                mTempCameraImagePath = image.getPath();
                Uri uriSavedImage = FileProvider.getUriForFile(mActivity,
                        mActivity.getApplicationContext().getPackageName() + ".apkgfileprovider", image);

                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                mActivity.startActivityForResult(cameraIntent, ACTIVITY_TAKE_PICTURE);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    // Chromebooks do not support camera capture yet.
    if (CompatHelper.isChromebook()) {
        mBtnCamera.setVisibility(View.INVISIBLE);
    }

    layout.addView(mImagePreview, android.view.ViewGroup.LayoutParams.FILL_PARENT, p);
    layout.addView(mBtnGallery, android.view.ViewGroup.LayoutParams.FILL_PARENT);
    layout.addView(mBtnCamera, android.view.ViewGroup.LayoutParams.FILL_PARENT);
}

From source file:mobisocial.musubi.objects.WebAppObj.java

@Override
public View createView(Context context, ViewGroup parent) {
    LinearLayout frame = new LinearLayout(context);
    frame.setLayoutParams(CommonLayouts.FULL_WIDTH);
    frame.setOrientation(LinearLayout.VERTICAL);

    LinearLayout appBar = new LinearLayout(context);
    appBar.setLayoutParams(CommonLayouts.FULL_WIDTH);
    appBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(appBar);//from w  w w.  j  a v  a2  s . c  om

    Drawable icon = context.getResources().getDrawable(R.drawable.ic_menu_globe);
    ImageView iv = new ImageView(context);
    iv.setImageDrawable(icon);
    iv.setAdjustViewBounds(true);
    iv.setMaxWidth(60);
    iv.setMaxHeight(60);
    iv.setLayoutParams(CommonLayouts.WRAPPED);
    appBar.addView(iv);

    TextView tv = new TextView(context);
    tv.setLayoutParams(CommonLayouts.WRAPPED);
    tv.setGravity(Gravity.CENTER_VERTICAL);
    appBar.addView(tv);

    LinearLayout actionBar = new LinearLayout(context);
    actionBar.setLayoutParams(CommonLayouts.WRAPPED);
    actionBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(actionBar);

    Button b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setText("Run");
    b.setOnClickListener(getRunListener());
    actionBar.addView(b);

    b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setOnClickListener(getAddListener());
    actionBar.addView(b);

    return frame;
}

From source file:jp.ne.sakura.kkkon.java.net.socketimpl.testapp.android.SocketImplHookTestApp.java

/** Called when the activity is first created. */
@Override/*from  w  w w . j a  v  a 2  s  . com*/
public void onCreate(Bundle savedInstanceState) {
    final Context context = this.getApplicationContext();

    {
        SocketImplHookFactory.initialize();
    }
    {
        ProxySelector proxySelector = ProxySelector.getDefault();
        Log.d(TAG, "proxySelector=" + proxySelector);
        if (null != proxySelector) {
            URI uri = null;
            try {
                uri = new URI("http://www.google.com/");
            } catch (URISyntaxException e) {
                Log.d(TAG, e.toString());
            }
            List<Proxy> proxies = proxySelector.select(uri);
            if (null != proxies) {
                for (final Proxy proxy : proxies) {
                    Log.d(TAG, " proxy=" + proxy);
                }
            }
        }
    }

    super.onCreate(savedInstanceState);

    /* Create a TextView and set its content.
     * the text is retrieved by calling a native
     * function.
     */
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);

    TextView tv = new TextView(this);
    tv.setText("ExceptionHandler");
    layout.addView(tv);

    Button btn1 = new Button(this);
    btn1.setText("invoke Exception");
    btn1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final int count = 2;
            int[] array = new int[count];
            int value = array[count]; // invoke IndexOutOfBOundsException
        }
    });
    layout.addView(btn1);

    {
        Button btn = new Button(this);
        btn.setText("upload http AsyncTask");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() {

                    @Override
                    protected Boolean doInBackground(String... paramss) {
                        Boolean result = true;
                        Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid());
                        try {
                            //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS)
                            Log.d(TAG, "fng=" + Build.FINGERPRINT);
                            final List<NameValuePair> list = new ArrayList<NameValuePair>(16);
                            list.add(new BasicNameValuePair("fng", Build.FINGERPRINT));

                            HttpPost httpPost = new HttpPost(paramss[0]);
                            //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) );
                            httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                            DefaultHttpClient httpClient = new DefaultHttpClient();
                            Log.d(TAG, "socket.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                            Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                            httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
                                    new Integer(5 * 1000));
                            httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                                    new Integer(5 * 1000));
                            Log.d(TAG, "socket.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                            Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                            // <uses-permission android:name="android.permission.INTERNET"/>
                            // got android.os.NetworkOnMainThreadException, run at UI Main Thread
                            HttpResponse response = httpClient.execute(httpPost);
                            Log.d(TAG, "response=" + response.getStatusLine().getStatusCode());
                        } catch (Exception e) {
                            Log.d(TAG, "got Exception. msg=" + e.getMessage(), e);
                            result = false;
                        }
                        Log.d(TAG, "upload finish");
                        return result;
                    }

                };

                asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug");
                asyncTask.isCancelled();
            }
        });
        layout.addView(btn);
    }

    {
        Button btn = new Button(this);
        btn.setText("pre DNS query(0.0.0.0)");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                isReachable = false;
                Thread thread = new Thread(new Runnable() {

                    public void run() {
                        try {
                            destHost = InetAddress.getByName("0.0.0.0");
                            if (null != destHost) {
                                try {
                                    if (destHost.isReachable(5 * 1000)) {
                                        Log.d(TAG, "destHost=" + destHost.toString() + " reachable");
                                    } else {
                                        Log.d(TAG, "destHost=" + destHost.toString() + " not reachable");
                                    }
                                } catch (IOException e) {

                                }
                            }
                        } catch (UnknownHostException e) {

                        }
                        Log.d(TAG, "destHost=" + destHost);
                    }
                });
                thread.start();
                try {
                    thread.join(1000);
                } catch (InterruptedException e) {

                }
            }
        });
        layout.addView(btn);
    }
    {
        Button btn = new Button(this);
        btn.setText("pre DNS query(www.google.com)");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                isReachable = false;
                Thread thread = new Thread(new Runnable() {

                    public void run() {
                        try {
                            InetAddress dest = InetAddress.getByName("www.google.com");
                            if (null == dest) {
                                dest = destHost;
                            }
                            if (null != dest) {
                                try {
                                    if (dest.isReachable(5 * 1000)) {
                                        Log.d(TAG, "destHost=" + dest.toString() + " reachable");
                                        isReachable = true;
                                    } else {
                                        Log.d(TAG, "destHost=" + dest.toString() + " not reachable");
                                    }
                                    destHost = dest;
                                } catch (IOException e) {

                                }
                            } else {
                            }
                        } catch (UnknownHostException e) {
                            Log.d(TAG, "dns error" + e.toString());
                            destHost = null;
                        }
                        {
                            if (null != destHost) {
                                Log.d(TAG, "destHost=" + destHost);
                            }
                        }
                    }
                });
                thread.start();
                try {
                    thread.join();
                    {
                        final String addr = (null == destHost) ? ("") : (destHost.toString());
                        final String reachable = (isReachable) ? ("reachable") : ("not reachable");
                        Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable,
                                Toast.LENGTH_LONG);
                        toast.show();
                    }
                } catch (InterruptedException e) {

                }
            }
        });
        layout.addView(btn);
    }

    {
        Button btn = new Button(this);
        btn.setText("pre DNS query(kkkon.sakura.ne.jp)");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                isReachable = false;
                Thread thread = new Thread(new Runnable() {

                    public void run() {
                        try {
                            InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp");
                            if (null == dest) {
                                dest = destHost;
                            }
                            if (null != dest) {
                                try {
                                    if (dest.isReachable(5 * 1000)) {
                                        Log.d(TAG, "destHost=" + dest.toString() + " reachable");
                                        isReachable = true;
                                    } else {
                                        Log.d(TAG, "destHost=" + dest.toString() + " not reachable");
                                    }
                                    destHost = dest;
                                } catch (IOException e) {

                                }
                            } else {
                            }
                        } catch (UnknownHostException e) {
                            Log.d(TAG, "dns error" + e.toString());
                            destHost = null;
                        }
                        {
                            if (null != destHost) {
                                Log.d(TAG, "destHost=" + destHost);
                            }
                        }
                    }
                });
                thread.start();
                try {
                    thread.join();
                    {
                        final String addr = (null == destHost) ? ("") : (destHost.toString());
                        final String reachable = (isReachable) ? ("reachable") : ("not reachable");
                        Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable,
                                Toast.LENGTH_LONG);
                        toast.show();
                    }
                } catch (InterruptedException e) {

                }
            }
        });
        layout.addView(btn);
    }

    setContentView(layout);
}

From source file:com.matthewtamlin.sliding_intro_screen_manual_testing.TestPageLock.java

/**
 * @return creates a Button which navigates to the last page
 */// ww  w .j  av  a  2  s .  c  om
private Button createGoToLastPageButton() {
    final Button button = new Button(this);
    button.setText("Go to last page");

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final int startIndex = getIndexOfCurrentPage();
            goToLastPage();
            validateCommandPageChange(startIndex, numberOfPages() - 1);
        }
    });

    return button;
}