Example usage for android.widget TextView getText

List of usage examples for android.widget TextView getText

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public CharSequence getText() 

Source Link

Document

Return the text that TextView is displaying.

Usage

From source file:com.cachirulop.moneybox.activity.MovementDetailActivity.java

/**
 * Handles the click of the save button. Copy the values of the window in
 * the movement object and save in the database using the MovementManager
 * class./*from w  w w.ja va2 s . c  o  m*/
 */
public void onSaveClick() {
    TextView txt;
    Spinner amount;
    CurrencyValueDef c;

    txt = (TextView) findViewById(R.id.txtDescription);
    amount = (Spinner) findViewById(R.id.sAmount);

    c = (CurrencyValueDef) amount.getSelectedItem();

    _movement.setAmount(c.getAmount());
    _movement.setDescription(txt.getText().toString());

    MovementsManager.updateMovement(_movement);

    exitActivity(RESULT_OK);
}

From source file:com.github.wakhub.monodict.activity.FlashcardActivity.java

@OnActivityResult(REQUEST_CODE_SELECT_DIRECTORY_TO_EXPORT)
void onActivityResultSelectDirectoryToExport(int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;/*w  ww . java2 s.c  o  m*/
    }
    String path = data.getExtras().getString(DirectorySelectorActivity.RESULT_INTENT_PATH);

    String defaultPath = String.format("%s/%s-%s.json", path, getResources().getString(R.string.app_name),
            DateTimeUtils.getInstance().getCurrentDateTimeString());
    activityHelper.buildInputDialog(defaultPath, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            TextView textView = (TextView) ((Dialog) dialogInterface).findViewById(android.R.id.text1);
            String outputPath = textView.getText().toString();
            exportCardsTo(outputPath);
        }
    }).setTitle(R.string.action_export).show();
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private void refreshAnnotationNumber(ViewGroup viewGroup) {
    if (viewGroup != null) {
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            View child = viewGroup.getChildAt(i);
            if (child instanceof TextAnnotationView) {
                TextView textView = (((TextAnnotationView) child).getAnnotationNumberView());
                String newAnnotationNumber = Integer
                        .toString(Integer.valueOf(textView.getText().toString()) - 1);
                if (Integer.valueOf(newAnnotationNumber) != 0) {
                    textView.setText(newAnnotationNumber);
                }//from w w w. jav  a  2 s  .co  m
            }
        }
    }
}

From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            tab.setTextSize(16);/*from   ww w  . jav a2 s  . c o m*/
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.abcvoipsip.ui.dialpad.DialerFragment.java

@Override
public void placeVMCall() {
    Long accountToUse = SipProfile.INVALID_ID;
    SipProfile acc = null;/*  w w  w. j  a v  a  2 s. c o m*/
    acc = accountChooserButton.getSelectedAccount();
    if (acc != null) {
        accountToUse = acc.id;
    }

    if (accountToUse >= 0) {
        SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id,
                new String[] { SipProfile.FIELD_VOICE_MAIL_NBR });
        if (!TextUtils.isEmpty(vmAcc.vm_nbr)) {
            // Account already have a VM number
            try {
                service.makeCall(vmAcc.vm_nbr, (int) acc.id);
            } catch (RemoteException e) {
                Log.e(THIS_FILE, "Service can't be called to make the call");
            }
        } else {
            // Account has no VM number, propose to create one
            final long editedAccId = acc.id;
            LayoutInflater factory = LayoutInflater.from(getActivity());
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(acc.display_name)
                    .setView(textEntryView)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            if (missingVoicemailDialog != null) {
                                TextView tf = (TextView) missingVoicemailDialog.findViewById(R.id.vmfield);
                                if (tf != null) {
                                    String vmNumber = tf.getText().toString();
                                    if (!TextUtils.isEmpty(vmNumber)) {
                                        ContentValues cv = new ContentValues();
                                        cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber);

                                        int updated = getActivity().getContentResolver()
                                                .update(ContentUris.withAppendedId(
                                                        SipProfile.ACCOUNT_ID_URI_BASE, editedAccId), cv, null,
                                                        null);
                                        Log.d(THIS_FILE, "Updated accounts " + updated);
                                    }
                                }
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    } else if (accountToUse == CallHandler.getAccountIdForCallHandler(getActivity(),
            "com.abcvoipsip/com.abcvoipsip.plugins.telephony.CallHandler")) {
        // Case gsm voice mail
        TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String vmNumber = tm.getVoiceMailNumber();

        if (!TextUtils.isEmpty(vmNumber)) {
            OutgoingCall.ignoreNext = vmNumber;
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm)
                    .setMessage(R.string.no_voice_mail_configured)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    }
    // TODO : manage others ?... for now, no way to do so cause no vm stored
}

From source file:com.heath_bar.tvdb.SeriesOverview.java

@Override
public void onDialogPositiveClick(DialogFragment dialog) {
    TextView valueText = (TextView) dialog.getDialog().findViewById(R.id.value);
    new UpdateRatingTask().execute(userAccountId, String.valueOf(seriesId), valueText.getText().toString());
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

/**
 * Layout suggestions to the suggestions strip. And returns the start index of more
 * suggestions./*  ww w.j ava  2s .  c  o  m*/
 *
 * @param suggestedWords suggestions to be shown in the suggestions strip.
 * @param stripView the suggestions strip view.
 * @param placerView the view where the debug info will be placed.
 * @return the start index of more suggestions.
 */
public int layoutAndReturnStartIndexOfMoreSuggestions(final SuggestedWords suggestedWords,
        final ViewGroup stripView, final ViewGroup placerView) {
    if (suggestedWords.isPunctuationSuggestions()) {
        return layoutPunctuationsAndReturnStartIndexOfMoreSuggestions((PunctuationSuggestions) suggestedWords,
                stripView);
    }

    final int startIndexOfMoreSuggestions = setupWordViewsAndReturnStartIndexOfMoreSuggestions(suggestedWords,
            mSuggestionsCountInStrip);
    final TextView centerWordView = mWordViews.get(mCenterPositionInStrip);
    final int stripWidth = stripView.getWidth();
    final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, stripWidth);
    if (suggestedWords.size() == 1 || getTextScaleX(centerWordView.getText(), centerWidth,
            centerWordView.getPaint()) < MIN_TEXT_XSCALE) {
        // Layout only the most relevant suggested word at the center of the suggestion strip
        // by consolidating all slots in the strip.
        final int countInStrip = 1;
        mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
        layoutWord(mCenterPositionInStrip, stripWidth - mPadding);
        stripView.addView(centerWordView);
        setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT);
        if (SuggestionStripView.DBG) {
            layoutDebugInfo(mCenterPositionInStrip, placerView, stripWidth);
        }
        final Integer lastIndex = (Integer) centerWordView.getTag();
        return (lastIndex == null ? 0 : lastIndex) + 1;
    }

    final int countInStrip = mSuggestionsCountInStrip;
    mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
    int x = 0;
    for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
        if (positionInStrip != 0) {
            final View divider = mDividerViews.get(positionInStrip);
            // Add divider if this isn't the left most suggestion in suggestions strip.
            addDivider(stripView, divider);
            x += divider.getMeasuredWidth();
        }

        final int width = getSuggestionWidth(positionInStrip, stripWidth);
        final TextView wordView = layoutWord(positionInStrip, width);
        stripView.addView(wordView);
        setLayoutWeight(wordView, getSuggestionWeight(positionInStrip), ViewGroup.LayoutParams.MATCH_PARENT);
        x += wordView.getMeasuredWidth();

        if (SuggestionStripView.DBG) {
            layoutDebugInfo(positionInStrip, placerView, x);
        }
    }
    return startIndexOfMoreSuggestions;
}

From source file:com.github.irshulx.Components.InputExtensions.java

public TextView insertEditText(int position, String hint, CharSequence text) {
    String nextHint = isLastText(position) ? null : editorCore.getPlaceHolder();
    if (editorCore.getRenderType() == RenderType.Editor) {

        /**// w ww  .j  a v a 2 s. c o  m
         * when user press enter from first line without keyin anything, need to remove the placeholder from that line 0...
         */
        if (position == 1) {
            View view = editorCore.getParentView().getChildAt(0);
            EditorType type = editorCore.getControlType(view);
            if (type == EditorType.INPUT) {
                TextView textView = (TextView) view;
                if (TextUtils.isEmpty(textView.getText())) {
                    textView.setHint(null);
                }
            }
        }

        final CustomEditText view = getNewEditTextInst(nextHint, text);
        editorCore.getParentView().addView(view, position);
        editorCore.setActiveView(view);
        final android.os.Handler handler = new android.os.Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                setFocus(view);
            }
        }, 0);
        editorCore.setActiveView(view);
        return view;
    } else {
        final TextView view = getNewTextView(text);
        view.setTag(editorCore.createTag(EditorType.INPUT));
        editorCore.getParentView().addView(view);
        return view;
    }
}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

private View.OnClickListener makeInsertAttachmentOnClickListener(final Button insertButton,
        final TextView namespaceTextView, final EditText typeEditText, final EditText dataEditText) {
    return new View.OnClickListener() {
        @Override/*ww  w.  j av  a2s.co  m*/
        public void onClick(View v) {
            final String namespace = namespaceTextView.getText().toString();
            if (namespace.length() == 0) {
                toast("namespace cannot be empty");
                return;
            }
            final String type = typeEditText.getText().toString();
            if (type.length() == 0) {
                toast("type cannot be empty");
                return;
            }
            final String data = dataEditText.getText().toString();
            if (data.length() == 0) {
                toast("data cannot be empty");
                return;
            }

            Utils.setEnabledViews(false, insertButton);
            JSONObject body = buildCreateAttachmentJsonBody(namespace, type, data);

            Callback createAttachmentCallback = new Callback() {
                @Override
                public void onFailure(Request request, IOException e) {
                    logErrorAndToast("Failed request: " + request, e);
                    Utils.setEnabledViews(false, insertButton);
                }

                @Override
                public void onResponse(Response response) throws IOException {
                    String body = response.body().string();
                    if (response.isSuccessful()) {
                        try {
                            JSONObject json = new JSONObject(body);
                            attachmentsTable.addView(makeAttachmentRow(json), 2);
                            namespaceTextView.setText(namespace);
                            typeEditText.setText("");
                            typeEditText.requestFocus();
                            dataEditText.setText("");
                            insertButton.setEnabled(true);
                        } catch (JSONException e) {
                            logErrorAndToast("JSONException in building attachment data", e);
                        }
                    } else {
                        logErrorAndToast("Unsuccessful createAttachment request: " + body);
                    }
                    Utils.setEnabledViews(true, insertButton);
                }
            };

            client.createAttachment(createAttachmentCallback, beacon.getBeaconName(), body);
        }
    };
}

From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java

private void setOnclick() {
    mRecordImage.setOnClickListener(new OnClickListener() {
        @Override//from   w  w  w.  j  a  v a  2  s .c o  m
        public void onClick(View v) {
            try {
                JSONObject ret = new JSONObject();
                ret.put("eventType", "record");
                mUZContext.success(ret, false);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

    deleteTextImg.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            mEditText.setText("");
            if (config.showRecordBtn) {
                mRecordImage.setVisibility(View.VISIBLE);
            } else {
                mRecordImage.setVisibility(View.GONE);
            }
        }
    });

    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long longid) {
            if (position == list.size() - 1) {
                hide();
                id = 0;
                list.clear();
                list.add(relativeLayoutClean);
                adapter.notifyDataSetChanged();
                editor.clear();
                editor.commit();
            } else {
                int tv_listId = UZResourcesIDFinder.getResIdID("tv_listview");
                TextView tv = (TextView) view.findViewById(tv_listId);
                String searchText = tv.getText().toString();
                try {
                    JSONObject ret = new JSONObject();
                    ret.put("eventType", "history");
                    ret.put("text", searchText);
                    mUZContext.success(ret, false);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                SearchBarActivity.this.finish();
            }
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (!TextUtils.isEmpty(arg0)) {
                mRecordImage.setVisibility(View.GONE);
                deleteTextImg.setVisibility(View.VISIBLE);
            } else {
                deleteTextImg.setVisibility(View.GONE);
                if (config.showRecordBtn) {
                    mRecordImage.setVisibility(View.VISIBLE);
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        @Override
        public void afterTextChanged(Editable arg0) {

        }
    });

    mEditText.setOnEditorActionListener(new OnEditorActionListener() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean onEditorAction(TextView arg0, int actionId, KeyEvent event) {

            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                id++;
                String text = mEditText.getText().toString();
                if (!TextUtils.isEmpty(text)) {

                    if (recordCount <= 0) {

                        try {
                            JSONObject ret = new JSONObject();
                            ret.put("eventType", "search");
                            ret.put("text", text);
                            mUZContext.success(ret, false);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        SearchBarActivity.this.finish();
                        clearText();

                        return false;
                    }

                    int index = id % recordCount;
                    if (id > recordCount) {

                        editor.remove(1 + "");
                        editor.commit();
                        Map<String, String> map = (Map<String, String>) mPref.getAll();
                        if (map != null) {
                            if (map.size() != 0) {
                                for (int i = 1; i <= (map.size() + 1); i++) {
                                    for (Entry<String, String> iterable_element : map.entrySet()) {
                                        String key = iterable_element.getKey();
                                        if ((i + "").equals(key)) {
                                            editor.putString((i - 1) + "", iterable_element.getValue());
                                            editor.commit();
                                        }
                                    }
                                }
                            }
                        }
                        editor.putString(recordCount + "", text);
                        editor.commit();
                    } else {
                        editor.putString((index == 0 ? recordCount : index) + "", text);
                        editor.commit();
                    }

                    try {
                        JSONObject ret = new JSONObject();
                        ret.put("eventType", "search");
                        ret.put("text", text);
                        mUZContext.success(ret, false);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    SearchBarActivity.this.finish();
                    clearText();
                }

            }
            return false;
        }
    });

    mTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            SearchBarActivity.this.finish();
            clearText();

        }
    });
}