Example usage for android.widget RadioButton setChecked

List of usage examples for android.widget RadioButton setChecked

Introduction

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

Prototype

@Override
public void setChecked(boolean checked) 

Source Link

Document

Changes the checked state of this button.

Usage

From source file:com.bonsai.wallet32.SweepKeyActivity.java

private void addAccountRow(TableLayout table, int acctId, String acctName, long btc, double fiat) {
    TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.receive_to_row, table, false);

    RadioButton tv0 = (RadioButton) row.findViewById(R.id.to_account);
    tv0.setId(acctId); // Change id to the acctId.
    tv0.setText(acctName);/*from w  ww  . j a va 2s .co m*/
    tv0.setOnCheckedChangeListener(mReceiveToListener);
    if (acctId == mAccountId)
        tv0.setChecked(true);

    TextView tv1 = (TextView) row.findViewById(R.id.row_btc);
    tv1.setText(String.format("%s", mBTCFmt.formatCol(btc, 0, true, true)));

    TextView tv2 = (TextView) row.findViewById(R.id.row_fiat);
    tv2.setText(String.format("%.02f", fiat));

    table.addView(row);
}

From source file:org.ounl.lifelonglearninghub.fcube.navigate.SwipeFragmentActivity.java

/**
 * On click one radiobutton, deslect the rest of the radiobuttons
 * /*w w  w  .  ja  va  2  s.c  o m*/
 * @param v
 */
public void onSelectRadioButton(View v) {

    LinearLayout llRadioButton = (LinearLayout) v.getParent();
    LinearLayout llBranch = (LinearLayout) llRadioButton.getParent();
    LinearLayout llRoot = (LinearLayout) llBranch.getParent();

    RadioButton rbF = (RadioButton) llRoot.findViewById(R.id.rbFade);
    RadioButton rbRainbow = (RadioButton) llRoot.findViewById(R.id.rbRainbow);
    RadioButton rbRainbowC = (RadioButton) llRoot.findViewById(R.id.rbRainbowCircle);

    String sTag = v.getTag().toString();
    if (getString(R.string.rb_fade).compareTo(sTag) == 0) {

        rbRainbow.setChecked(false);
        rbRainbowC.setChecked(false);

    } else if (getString(R.string.rb_rainbow).compareTo(sTag) == 0) {

        rbF.setChecked(false);
        rbRainbowC.setChecked(false);

    } else if (getString(R.string.rb_rainbow_circle).compareTo(sTag) == 0) {

        rbF.setChecked(false);
        rbRainbow.setChecked(false);

    }

}

From source file:org.anhonesteffort.flock.SelectServiceProviderFragment.java

private void initRadioButtons(View fragmentView) {
    final LinearLayout rowSelectOws = (LinearLayout) fragmentView.findViewById(R.id.row_service_ows);
    final LinearLayout rowSelectOther = (LinearLayout) fragmentView.findViewById(R.id.row_service_other);
    final RadioButton radioButtonOws = (RadioButton) fragmentView.findViewById(R.id.radio_button_service_ows);
    final RadioButton radioButtonOther = (RadioButton) fragmentView
            .findViewById(R.id.radio_button_service_other);
    final TextView serviceDescription = (TextView) fragmentView.findViewById(R.id.sync_service_description);
    final Double costPerYearUsd = (double) getResources().getInteger(R.integer.cost_per_year_usd);

    rowSelectOws.setOnClickListener(new View.OnClickListener() {

        @Override/*  w w w . j  av a  2  s .  co  m*/
        public void onClick(View view) {
            if (!radioButtonOws.isChecked()) {
                radioButtonOws.setChecked(true);
                radioButtonOther.setChecked(false);
                serviceDescription.setText(Html.fromHtml(
                        getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available,
                                costPerYearUsd)));
                serviceDescription.setMovementMethod(LinkMovementMethod.getInstance());
            }
        }

    });

    rowSelectOther.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!radioButtonOther.isChecked()) {
                radioButtonOther.setChecked(true);
                radioButtonOws.setChecked(false);
                serviceDescription
                        .setText(R.string.you_may_chose_to_run_and_configure_your_own_webdav_compliant_server);
            }
        }

    });

    radioButtonOws.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (isChecked) {
                radioButtonOws.setChecked(true);
                radioButtonOther.setChecked(false);
                serviceDescription.setText(Html.fromHtml(
                        getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available,
                                costPerYearUsd)));
                serviceDescription.setMovementMethod(LinkMovementMethod.getInstance());
            }
        }

    });

    radioButtonOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (isChecked) {
                radioButtonOther.setChecked(true);
                radioButtonOws.setChecked(false);
                serviceDescription
                        .setText(R.string.you_may_chose_to_run_and_configure_your_own_webdav_compliant_server);
            }
        }

    });
}

From source file:com.trimph.toprand.trimphrxandroid.trimph.ui.main.news.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    RadioButton tab = new RadioButton(getContext());
    tab.setButtonDrawable(null);/*from   w ww . j  a va  2 s.  co  m*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tab.setCompoundDrawables(null, getContext().getDrawable(resId), null, null);
    }

    if (position == currentPosition) {
        tab.setChecked(true);
    } else {
        tab.setChecked(false);
    }

    addTab(position, tab);
}

From source file:com.google.android.apps.mytracks.fragments.ChooseUploadServiceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    sendRequest = getArguments().getParcelable(KEY_SEND_REQUEST);
    View view = getActivity().getLayoutInflater().inflate(R.layout.choose_upload_service, null);

    mapsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_maps);
    fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_fusion_tables);
    docsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_docs);

    mapsCheckBox.setChecked(PreferencesUtils.getBoolean(getActivity(), R.string.send_to_maps_key,
            PreferencesUtils.SEND_TO_MAPS_DEFAULT));
    fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(getActivity(),
            R.string.send_to_fusion_tables_key, PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
    docsCheckBox.setChecked(PreferencesUtils.getBoolean(getActivity(), R.string.send_to_docs_key,
            PreferencesUtils.SEND_TO_DOCS_DEFAULT));

    mapsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton button, boolean checked) {
            updateMapsOption();//from w  w w .ja  v  a 2s .  c o m
        }
    });

    mapsOptionTableRow = (TableRow) view.findViewById(R.id.choose_upload_service_maps_options);

    RadioButton newMapRadioButton = (RadioButton) view.findViewById(R.id.choose_upload_service_new_map);
    boolean defaultMapPublic = PreferencesUtils.getBoolean(getActivity(), R.string.default_map_public_key,
            PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT);
    newMapRadioButton.setText(
            defaultMapPublic ? R.string.send_google_new_public_map : R.string.send_google_new_unlisted_map);

    existingMapRadioButton = (RadioButton) view.findViewById(R.id.choose_upload_service_existing_map);

    updateMapsOption();
    if (PreferencesUtils.getBoolean(getActivity(), R.string.pick_existing_map_key,
            PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
        existingMapRadioButton.setChecked(true);
    } else {
        newMapRadioButton.setChecked(true);
    }

    return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
            .setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    PreferencesUtils.setBoolean(getActivity(), R.string.pick_existing_map_key,
                            existingMapRadioButton.isChecked());
                    PreferencesUtils.setBoolean(getActivity(), R.string.send_to_maps_key,
                            mapsCheckBox.isChecked());
                    PreferencesUtils.setBoolean(getActivity(), R.string.send_to_fusion_tables_key,
                            fusionTablesCheckBox.isChecked());
                    PreferencesUtils.setBoolean(getActivity(), R.string.send_to_docs_key,
                            docsCheckBox.isChecked());
                    if (mapsCheckBox.isChecked() || fusionTablesCheckBox.isChecked()
                            || docsCheckBox.isChecked()) {
                        startNextActivity();
                    } else {
                        Toast.makeText(getActivity(), R.string.send_google_no_service_selected,
                                Toast.LENGTH_LONG).show();
                    }
                }
            }).setTitle(R.string.send_google_title).setView(view).create();
}

From source file:com.mobicage.rogerthat.SendMessageButtonActivity.java

private void addButton() {
    final View dialog = getLayoutInflater().inflate(R.layout.new_button_dialog, null);
    final TextInputLayout captionViewLayout = (TextInputLayout) dialog.findViewById(R.id.button_caption);
    mCaptionView = captionViewLayout.getEditText();
    mActionView = (EditText) dialog.findViewById(R.id.button_action);
    final ImageButton actionHelpButton = (ImageButton) dialog.findViewById(R.id.action_help_button);
    final RadioButton noneRadio = (RadioButton) dialog.findViewById(R.id.action_none);
    final RadioButton telRadio = (RadioButton) dialog.findViewById(R.id.action_tel);
    final RadioButton geoRadio = (RadioButton) dialog.findViewById(R.id.action_geo);
    final RadioButton wwwRadio = (RadioButton) dialog.findViewById(R.id.action_www);
    final int iconColor = LookAndFeelConstants.getPrimaryIconColor(SendMessageButtonActivity.this);
    noneRadio.setChecked(true);
    mActionView.setVisibility(View.GONE);
    actionHelpButton.setVisibility(View.GONE);
    noneRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override//from ww  w .jav  a  2s . c  o  m
        public void safeOnClick(View v) {
            mActionView.setVisibility(View.GONE);
            actionHelpButton.setVisibility(View.GONE);
        }
    });
    telRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_PHONE);
            actionHelpButton.setVisibility(View.VISIBLE);
            actionHelpButton.setImageDrawable(new IconicsDrawable(mService, FontAwesome.Icon.faw_address_book_o)
                    .color(iconColor).sizeDp(24));
        }
    });
    geoRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_TEXT);
            actionHelpButton.setVisibility(View.VISIBLE);
            actionHelpButton.setImageDrawable(
                    new IconicsDrawable(mService, FontAwesome.Icon.faw_map_marker).color(iconColor).sizeDp(24));
        }
    });
    wwwRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("http://");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_TEXT);
            actionHelpButton.setVisibility(View.GONE);
        }
    });
    actionHelpButton.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            if (telRadio.isChecked()) {
                Intent intent = new Intent(Intent.ACTION_PICK,
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
                startActivityForResult(intent, PICK_CONTACT);
            } else if (geoRadio.isChecked()) {
                Intent intent = new Intent(SendMessageButtonActivity.this, GetLocationActivity.class);
                startActivityForResult(intent, GET_LOCATION);
            }
        }
    });
    String message = getString(R.string.create_button_title);
    String positiveCaption = getString(R.string.ok);
    String negativeCaption = getString(R.string.cancel);
    SafeDialogClick positiveClick = new SafeDialogClick() {
        @Override
        public void safeOnClick(DialogInterface di, int id) {
            String caption = mCaptionView.getText().toString();
            if ("".equals(caption.trim())) {
                UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.caption_required));
                return;
            }

            CannedButton cannedButton;
            if (!noneRadio.isChecked()) {
                String actionText = mActionView.getText().toString();
                if ("".equals(caption.trim())) {
                    UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid));
                    return;
                }
                if (telRadio.isChecked()) {
                    actionText = "tel://" + actionText;
                } else if (geoRadio.isChecked()) {
                    actionText = "geo://" + actionText;
                }

                Matcher action = actionPattern.matcher(actionText);
                if (!action.matches()) {
                    UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid));
                    return;
                }
                cannedButton = new CannedButton(caption, "".equals(action.group(2)) ? null : action.group());

            } else {
                cannedButton = new CannedButton(caption, null);
            }

            mCannedButtons.add(cannedButton);
            cannedButton.setSelected(true);
            mCannedButtonAdapter.notifyDataSetChanged();
            mButtons.add(cannedButton.getId());
            di.dismiss();
        }
    };
    AlertDialog alertDialog = UIUtils.showDialog(SendMessageButtonActivity.this, null, message, positiveCaption,
            positiveClick, negativeCaption, null, dialog);
    alertDialog.setCanceledOnTouchOutside(true);
}

From source file:org.cowboycoders.cyclisimo.fragments.ChooseUploadServiceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    activity = getActivity();/*from w  w  w .j ava 2  s  . com*/
    sendRequest = getArguments().getParcelable(KEY_SEND_REQUEST);

    View view = activity.getLayoutInflater().inflate(R.layout.choose_upload_service, null);

    mapsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_maps);
    fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_fusion_tables);
    docsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_docs);

    mapsCheckBox.setChecked(PreferencesUtils.getBoolean(activity, R.string.send_to_maps_key,
            PreferencesUtils.SEND_TO_MAPS_DEFAULT));
    fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(activity, R.string.send_to_fusion_tables_key,
            PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
    docsCheckBox.setChecked(PreferencesUtils.getBoolean(activity, R.string.send_to_docs_key,
            PreferencesUtils.SEND_TO_DOCS_DEFAULT));

    mapsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton button, boolean checked) {
            updateMapsOption();
        }
    });

    mapsOptionTableRow = (TableRow) view.findViewById(R.id.choose_upload_service_maps_options);

    RadioButton newMapRadioButton = (RadioButton) view.findViewById(R.id.choose_upload_service_new_map);
    boolean defaultMapPublic = PreferencesUtils.getBoolean(activity, R.string.default_map_public_key,
            PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT);
    newMapRadioButton.setText(
            defaultMapPublic ? R.string.send_google_new_public_map : R.string.send_google_new_unlisted_map);

    existingMapRadioButton = (RadioButton) view.findViewById(R.id.choose_upload_service_existing_map);

    updateMapsOption();
    if (PreferencesUtils.getBoolean(activity, R.string.pick_existing_map_key,
            PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
        existingMapRadioButton.setChecked(true);
    } else {
        newMapRadioButton.setChecked(true);
    }

    return new AlertDialog.Builder(activity).setNegativeButton(R.string.generic_cancel, null)
            .setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    PreferencesUtils.setBoolean(activity, R.string.pick_existing_map_key,
                            existingMapRadioButton.isChecked());
                    PreferencesUtils.setBoolean(activity, R.string.send_to_maps_key, mapsCheckBox.isChecked());
                    PreferencesUtils.setBoolean(activity, R.string.send_to_fusion_tables_key,
                            fusionTablesCheckBox.isChecked());
                    PreferencesUtils.setBoolean(activity, R.string.send_to_docs_key, docsCheckBox.isChecked());
                    if (mapsCheckBox.isChecked() || fusionTablesCheckBox.isChecked()
                            || docsCheckBox.isChecked()) {
                        startNextActivity();
                    } else {
                        Toast.makeText(activity, R.string.send_google_no_service_selected, Toast.LENGTH_LONG)
                                .show();
                    }
                }
            }).setTitle(R.string.send_google_title).setView(view).create();
}

From source file:com.kunze.androidlocaltodo.TaskListActivity.java

private void ShowTaskDialog(Task task, OnClickListener okListener) {
    LayoutInflater inflater = this.getLayoutInflater();
    View dlgView = inflater.inflate(R.layout.dialog_task, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dlgView);/*from  w  w w.j a  v a  2s  .co  m*/
    builder.setTitle("Task");

    final TextView nameEdit = (TextView) dlgView.findViewById(R.id.task_name_edit);
    nameEdit.setText(task.mName);
    final TextView descriptionEdit = (TextView) dlgView.findViewById(R.id.task_description_edit);
    descriptionEdit.setText(task.mDescription);
    final TextView dueDateView = (TextView) dlgView.findViewById(R.id.task_due_date);
    SetFriendlyDueDateText(dueDateView, task.mDueDate);
    Button dueDateButton = (Button) dlgView.findViewById(R.id.task_due_date_choose);
    final Calendar dueDate = task.mDueDate;
    final Task thisTask = task;
    dueDateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ShowDueDateDialog(dueDate, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int id) {
                    Dialog dlg = (Dialog) dialogInterface;
                    DatePicker datePicker = (DatePicker) dlg.findViewById(R.id.due_date_calendar);
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
                    thisTask.mDueDate = calendar;
                    SetFriendlyDueDateText(dueDateView, thisTask.mDueDate);
                }
            });
        }
    });

    final CheckBox repeatCheck = (CheckBox) dlgView.findViewById(R.id.repeat);
    repeatCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            View dialog = (View) buttonView.getParent();
            SetRepeatVisibility(dialog, isChecked);
        }
    });

    Boolean repeat = task.mRepeatUnit != Task.RepeatUnit.NONE;
    repeatCheck.setChecked(repeat);
    SetRepeatVisibility(dlgView, repeat);

    final EditText repeatTimeEdit = (EditText) dlgView.findViewById(R.id.repeat_time);
    repeatTimeEdit.setText(Integer.toString(task.mRepeatTime));

    final Spinner repeatUnitSpinner = (Spinner) dlgView.findViewById(R.id.repeat_unit);
    String[] repeatUnits = { "Days", "Weeks", "Months", "Years" };
    repeatUnitSpinner
            .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, repeatUnits));
    int repeatUnitPos = 0;
    switch (task.mRepeatUnit) {
    case DAYS:
        repeatUnitPos = 0;
        break;
    case WEEKS:
        repeatUnitPos = 1;
        break;
    case MONTHS:
        repeatUnitPos = 2;
        break;
    case YEARS:
        repeatUnitPos = 3;
        break;
    case NONE:
        repeatUnitPos = 0;
    }
    repeatUnitSpinner.setSelection(repeatUnitPos);

    final RadioButton repeatFromComplete = (RadioButton) dlgView.findViewById(R.id.repeat_from_complete);
    final RadioButton repeatFromDue = (RadioButton) dlgView.findViewById(R.id.repeat_from_due);
    if (task.mRepeatFromComplete) {
        repeatFromComplete.setChecked(true);
    } else {
        repeatFromDue.setChecked(true);
    }

    // Here's a trick:  We cascade the OnClick listeners so we can extract
    // the dialog contents into the task before calling the second listener.
    final OnClickListener userListener = okListener;
    final Task myTask = task;
    OnClickListener cascadedListener = new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            myTask.mName = nameEdit.getText().toString();
            myTask.mDescription = descriptionEdit.getText().toString();

            myTask.mRepeatUnit = Task.RepeatUnit.NONE;
            if (repeatCheck.isChecked()) {
                switch (repeatUnitSpinner.getSelectedItemPosition()) {
                case 0:
                    myTask.mRepeatUnit = Task.RepeatUnit.DAYS;
                    break;
                case 1:
                    myTask.mRepeatUnit = Task.RepeatUnit.WEEKS;
                    break;
                case 2:
                    myTask.mRepeatUnit = Task.RepeatUnit.MONTHS;
                    break;
                case 3:
                    myTask.mRepeatUnit = Task.RepeatUnit.YEARS;
                    break;
                }

                myTask.mRepeatTime = Integer.parseInt(repeatTimeEdit.getText().toString());
                myTask.mRepeatFromComplete = repeatFromComplete.isChecked();
            }

            userListener.onClick(dialog, which);
        }
    };

    builder.setNegativeButton("Cancel", null);
    builder.setPositiveButton("OK", cascadedListener);

    builder.show();
}

From source file:com.trimph.toprand.trimphrxandroid.trimph.ui.main.news.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    RadioButton tab = (RadioButton) LayoutInflater.from(getContext()).inflate(R.layout.view_radiobutton, null);
    tab.setText(title);/* w  ww  . j  a  va  2 s  .co  m*/

    tab.setTextSize(tabTextSize);
    //        tab.setGravity(Gravity.CENTER);
    //        tab.setSingleLine();
    //        tab.setButtonDrawable(null);

    if (position == currentPosition) {
        tab.setChecked(true);
    } else {
        tab.setChecked(false);
    }
    addTab(position, tab);
}

From source file:com.kdao.cmpe235_project.UploadActivity.java

private void initUI() {
    /**//from   w ww . ja va  2s.  c o  m
     * This adapter takes the data in transferRecordMaps and displays it,
     * with the keys of the map being related to the columns in the adapter
     */
    simpleAdapter = new SimpleAdapter(this, transferRecordMaps, R.layout.record_item,
            new String[] { "checked", "fileName", "progress", "bytes", "state", "percentage" },
            new int[] { R.id.radioButton1, R.id.textFileName, R.id.progressBar1, R.id.textBytes, R.id.textState,
                    R.id.textPercentage });
    simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            switch (view.getId()) {
            case R.id.radioButton1:
                RadioButton radio = (RadioButton) view;
                radio.setChecked((Boolean) data);
                return true;
            case R.id.textFileName:
                TextView fileName = (TextView) view;
                fileName.setText((String) data);
                return true;
            case R.id.progressBar1:
                ProgressBar progress = (ProgressBar) view;
                progress.setProgress((Integer) data);
                return true;
            case R.id.textBytes:
                TextView bytes = (TextView) view;
                bytes.setText((String) data);
                return true;
            case R.id.textState:
                TextView state = (TextView) view;
                state.setText(((TransferState) data).toString());
                return true;
            case R.id.textPercentage:
                TextView percentage = (TextView) view;
                percentage.setText((String) data);
                return true;
            }
            return false;
        }
    });
    setListAdapter(simpleAdapter);

    // Updates checked index when an item is clicked
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) {

            if (checkedIndex != pos) {
                transferRecordMaps.get(pos).put("checked", true);
                if (checkedIndex >= 0) {
                    transferRecordMaps.get(checkedIndex).put("checked", false);
                }
                checkedIndex = pos;
                updateButtonAvailability();
                simpleAdapter.notifyDataSetChanged();
            }
        }
    });

    //btnUploadFile = (Button) findViewById(R.id.buttonUploadFile);
    btnUploadImage = (Button) findViewById(R.id.buttonUploadImage);
    btnUploadAudio = (Button) findViewById(R.id.buttonUploadAudio);
    btnUploadVideo = (Button) findViewById(R.id.buttonUploadVideo);
    btnPause = (Button) findViewById(R.id.buttonPause);
    btnResume = (Button) findViewById(R.id.buttonResume);
    btnCancel = (Button) findViewById(R.id.buttonCancel);
    btnDelete = (Button) findViewById(R.id.buttonDelete);
    btnPauseAll = (Button) findViewById(R.id.buttonPauseAll);
    btnCancelAll = (Button) findViewById(R.id.buttonCancelAll);

    btnUploadImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                System.out.println(">>>>> Start uploading photos... <<<<<<<");
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/photo";
                intent.setType("image/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }
    });

    btnUploadAudio.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/audio";
                intent.setType("audio/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }

    });

    btnUploadVideo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/video";
                intent.setType("video/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }
    });

    btnPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure the user has selected a transfer
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                Boolean paused = transferUtility.pause(observers.get(checkedIndex).getId());
                /**
                 * If paused does not return true, it is likely because the
                 * user is trying to pause an upload that is not in a
                 * pausable state (For instance it is already paused, or
                 * canceled).
                 */
                if (!paused) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_PAUSE_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnResume.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure the user has selected a transfer
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                TransferObserver resumed = transferUtility.resume(observers.get(checkedIndex).getId());
                // Sets a new transfer listener to the original observer.
                // This will overwrite existing listener.
                observers.get(checkedIndex).setTransferListener(new UploadListener());
                /**
                 * If resume returns null, it is likely because the transfer
                 * is not in a resumable state (For instance it is already
                 * running).
                 */
                if (resumed == null) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_RESUME_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure a transfer is selected
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                Boolean canceled = transferUtility.cancel(observers.get(checkedIndex).getId());
                /**
                 * If cancel returns false, it is likely because the
                 * transfer is already canceled
                 */
                if (!canceled) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_TRANSFER_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnDelete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure a transfer is selected
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                transferUtility.deleteTransferRecord(observers.get(checkedIndex).getId());
                observers.remove(checkedIndex);
                transferRecordMaps.remove(checkedIndex);
                checkedIndex = INDEX_NOT_CHECKED;
                updateButtonAvailability();
                updateList();
            }
        }
    });

    btnPauseAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            transferUtility.pauseAllWithType(TransferType.UPLOAD);
        }
    });

    btnCancelAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            transferUtility.cancelAllWithType(TransferType.UPLOAD);
        }
    });

    updateButtonAvailability();
}