Example usage for android.widget EditText setText

List of usage examples for android.widget EditText setText

Introduction

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

Prototype

@Override
    public void setText(CharSequence text, BufferType type) 

Source Link

Usage

From source file:com.oliversride.wordryo.Utils.java

public static void setText(Dialog dialog, int id, String value) {
    EditText editText = (EditText) dialog.findViewById(id);
    if (null != editText) {
        editText.setText(value, TextView.BufferType.EDITABLE);
    }//from w  ww.ja  v  a 2 s. c om
}

From source file:com.oliversride.wordryo.Utils.java

public static void setText(Activity activity, int id, String value) {
    EditText editText = (EditText) activity.findViewById(id);
    if (null != editText) {
        editText.setText(value, TextView.BufferType.EDITABLE);
    }//  w  w w .  java2s .  c  om
}

From source file:com.vanitysoft.reapefire.android.MainActivity.java

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

    setContentView(R.layout.main_activity_layout);

    EditText editText = (EditText) findViewById(R.id.username);
    editText.setText("geokoala", BufferType.EDITABLE);

    EditText editTextPassword = (EditText) findViewById(R.id.password);
    editTextPassword.setText("fbde14be-bfc5-496f-a56b-6df55644ff27", BufferType.EDITABLE);

    EditText editTextAppKey = (EditText) findViewById(R.id.accountKey);
    editTextAppKey.setText("393233d9-7997-4649-8291-73102d4b7358", BufferType.EDITABLE);

    // Initiate the request to the protected service
    final Button submitButton = (Button) findViewById(R.id.submit);

    submitButton.setOnClickListener(new View.OnClickListener() {
        @Override//from  ww  w.j  a  va  2 s .  com
        public void onClick(View v) {
            new FetchSecuredResourceTask().execute();
        }
    });

}

From source file:com.example.travelclaims.NewClaimActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.addnewclaim);

    StartDateEdit = (EditText) findViewById(R.id.editStartDate);
    EndDateEdit = (EditText) findViewById(R.id.editEndDate);

    if (MainActivity.edit) {
        ClaimList cl = new ClaimList();
        cl.removeClaim(MainActivity.claim);
        EditText Destination = (EditText) findViewById(R.id.editDestination);
        EditText Description = (EditText) findViewById(R.id.description);
        Destination.setText(MainActivity.claim.getClaim(), TextView.BufferType.EDITABLE);
        StartDateEdit.setText(MainActivity.claim.getStartDate(), TextView.BufferType.EDITABLE);
        EndDateEdit.setText(MainActivity.claim.getEndDate(), TextView.BufferType.EDITABLE);
        Description.setText(MainActivity.claim.getDescription(), TextView.BufferType.EDITABLE);
        MainActivity.edit = false;/* www . ja  va2s .c o  m*/
    }
    set_on_click();
}

From source file:com.manzdagratiano.gobbledygook.Gobbledygook.java

private void setPassword(View view, String password) {
    EditText hash = (EditText) findViewById(R.id.hash);
    hash.setText(password, TextView.BufferType.EDITABLE);
}

From source file:com.gimranov.zandy.app.AttachmentActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final String attachmentKey = b.getString("attachmentKey");
    final String itemKey = b.getString("itemKey");
    final String content = b.getString("content");
    final String mode = b.getString("mode");
    AlertDialog dialog;/*from   w ww . jav a2s.c  o m*/
    switch (id) {
    case DIALOG_CONFIRM_NAVIGATE:
        dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.view_online_warning))
                .setPositiveButton(getResources().getString(R.string.view),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // The behavior for invalid URIs might be nasty, but
                                // we'll cross that bridge if we come to it.
                                try {
                                    Uri uri = Uri.parse(content);
                                    startActivity(new Intent(Intent.ACTION_VIEW).setData(uri));
                                } catch (ActivityNotFoundException e) {
                                    // There can be exceptions here; not sure what would prompt us to have
                                    // URIs that the browser can't load, but it apparently happens.
                                    Toast.makeText(getApplicationContext(), getResources()
                                            .getString(R.string.attachment_intent_failed_for_uri, content),
                                            Toast.LENGTH_SHORT).show();
                                }
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    case DIALOG_CONFIRM_DELETE:
        dialog = new AlertDialog.Builder(this)
                .setTitle(getResources().getString(R.string.attachment_delete_confirm))
                .setPositiveButton(getResources().getString(R.string.menu_delete),
                        new DialogInterface.OnClickListener() {
                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Attachment a = Attachment.load(attachmentKey, db);
                                a.delete(db);
                                ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter();
                                la.clear();
                                for (Attachment at : Attachment.forItem(Item.load(itemKey, db), db)) {
                                    la.add(at);
                                }
                            }
                        })
                .setNegativeButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    case DIALOG_NOTE:
        final EditText input = new EditText(this);
        input.setText(content, BufferType.EDITABLE);

        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setTitle(getResources().getString(R.string.note)).setView(input).setPositiveButton(
                        getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Editable value = input.getText();
                                String fixed = value.toString().replaceAll("\n\n", "\n<br>");
                                if (mode != null && mode.equals("new")) {
                                    Log.d(TAG, "Attachment created with parent key: " + itemKey);
                                    Attachment att = new Attachment(getBaseContext(), "note", itemKey);
                                    att.setNoteText(fixed);
                                    att.dirty = APIRequest.API_NEW;
                                    att.save(db);
                                } else {
                                    Attachment att = Attachment.load(attachmentKey, db);
                                    att.setNoteText(fixed);
                                    att.dirty = APIRequest.API_DIRTY;
                                    att.save(db);
                                }
                                ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter();
                                la.clear();
                                for (Attachment a : Attachment.forItem(Item.load(itemKey, db), db)) {
                                    la.add(a);
                                }
                                la.notifyDataSetChanged();
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        });
        // We only want the delete option when this isn't a new note
        if (mode == null || !"new".equals(mode)) {
            builder = builder.setNegativeButton(getResources().getString(R.string.menu_delete),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Bundle b = new Bundle();
                            b.putString("attachmentKey", attachmentKey);
                            b.putString("itemKey", itemKey);
                            removeDialog(DIALOG_CONFIRM_DELETE);
                            AttachmentActivity.this.b = b;
                            showDialog(DIALOG_CONFIRM_DELETE);
                        }
                    });
        }
        dialog = builder.create();
        return dialog;
    case DIALOG_FILE_PROGRESS:
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog
                .setMessage(getResources().getString(R.string.attachment_downloading, b.getString("title")));
        mProgressDialog.setIndeterminate(true);
        return mProgressDialog;
    default:
        Log.e(TAG, "Invalid dialog requested");
        return null;
    }
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

private void startEditTagsMode() {
    ImageButton editButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        editButton.setImageResource(R.drawable.ic_edit_anim);
        ((Animatable) editButton.getDrawable()).start();
    } else//from  w  w  w  .  j a  v a 2 s  .c om
        editButton.setImageResource(R.drawable.ic_done);

    ((DrawerLayout) ((MainActivity) getActivity()).drawer)
            .setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mRefreshLayout.setEnabled(false);
    getActivity().findViewById(R.id.refresh_fab).setEnabled(false);
    ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide();
    ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear();

    TextSwitcher textSwitcher = ((TextSwitcher) getActivity().findViewById(R.id.switcher));
    EditText songTV = (EditText) getActivity().findViewById(R.id.song);
    TextView artistTV = ((TextView) getActivity().findViewById(R.id.artist));

    EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity()));
    newLyrics.setText(((TextView) textSwitcher.getCurrentView()).getText(), TextView.BufferType.EDITABLE);

    textSwitcher.setVisibility(View.GONE);
    newLyrics.setVisibility(View.VISIBLE);

    songTV.setInputType(InputType.TYPE_CLASS_TEXT);
    artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
    songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
    artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);

    if (songTV.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) getActivity().getApplicationContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT);
    }
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(true);//from   w  ww  . j  a  va 2 s .  c o m
    setHasOptionsMenu(true);
    View layout = inflater.inflate(R.layout.lyrics_view, container, false);
    if (savedInstanceState != null)
        try {
            Lyrics l = Lyrics.fromBytes(savedInstanceState.getByteArray("lyrics"));
            if (l != null)
                this.mLyrics = l;
            mSearchQuery = savedInstanceState.getString("searchQuery");
            mSearchFocused = savedInstanceState.getBoolean("searchFocused");
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    else {
        Bundle args = getArguments();
        if (args != null)
            try {
                Lyrics lyrics = Lyrics.fromBytes(args.getByteArray("lyrics"));
                this.mLyrics = lyrics;
                if (lyrics != null && lyrics.getText() == null && lyrics.getArtist() != null) {
                    String artist = lyrics.getArtist();
                    String track = lyrics.getTitle();
                    String url = lyrics.getURL();
                    fetchLyrics(artist, track, url);
                    mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
                    startRefreshAnimation();
                }
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
    }
    if (layout != null) {
        Bundle args = savedInstanceState != null ? savedInstanceState : getArguments();

        boolean screenOn = PreferenceManager.getDefaultSharedPreferences(getActivity())
                .getBoolean("pref_force_screen_on", false);

        TextSwitcher textSwitcher = (TextSwitcher) layout.findViewById(R.id.switcher);
        textSwitcher.setFactory(new LyricsTextFactory(layout.getContext()));
        ActionMode.Callback callback = new CustomSelectionCallback(getActivity());
        ((TextView) textSwitcher.getChildAt(0)).setCustomSelectionActionModeCallback(callback);
        ((TextView) textSwitcher.getChildAt(1)).setCustomSelectionActionModeCallback(callback);
        textSwitcher.setKeepScreenOn(screenOn);
        layout.findViewById(R.id.lrc_view).setKeepScreenOn(screenOn);

        EditText artistTV = (EditText) getActivity().findViewById(R.id.artist);
        EditText songTV = (EditText) getActivity().findViewById(R.id.song);

        if (args != null && args.containsKey("editedLyrics")) {
            EditText editedLyrics = (EditText) layout.findViewById(R.id.edit_lyrics);
            textSwitcher.setVisibility(View.GONE);
            editedLyrics.setVisibility(View.VISIBLE);
            songTV.setInputType(InputType.TYPE_CLASS_TEXT);
            artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
            songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
            artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
            editedLyrics.setText(args.getCharSequence("editedLyrics"), TextView.BufferType.EDITABLE);
            songTV.setText(args.getCharSequence("editedTitle"), TextView.BufferType.EDITABLE);
            artistTV.setText(args.getCharSequence("editedArtist"), TextView.BufferType.EDITABLE);
        }

        artistTV.setTypeface(LyricsTextFactory.FontCache.get("regular", getActivity()));
        songTV.setTypeface(LyricsTextFactory.FontCache.get("medium", getActivity()));

        final RefreshIcon refreshFab = (RefreshIcon) getActivity().findViewById(R.id.refresh_fab);
        refreshFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mRefreshLayout.isRefreshing())
                    fetchCurrentLyrics(true);
            }
        });
        if (args != null)
            refreshFab.setEnabled(args.getBoolean("refreshFabEnabled", true));

        mScrollView = (NestedScrollView) layout.findViewById(R.id.scrollview);
        mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
        TypedValue primaryColor = new TypedValue();
        TypedValue accentColor = new TypedValue();
        getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true);
        getActivity().getTheme().resolveAttribute(R.attr.colorAccent, accentColor, true);
        mRefreshLayout.setColorSchemeResources(primaryColor.resourceId, accentColor.resourceId);
        float offset = getResources().getDisplayMetrics().density * 64;
        mRefreshLayout.setProgressViewEndTarget(true, (int) offset);
        mRefreshLayout.setOnRefreshListener(this);

        final ImageButton editTagsButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn);

        View.OnClickListener startEditClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startEditTagsMode();
                final View.OnClickListener startEditClickListener = this;
                editTagsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        exitEditTagsMode();
                        editTagsButton.setOnClickListener(startEditClickListener);
                    }
                });
            }
        };
        editTagsButton.setOnClickListener(startEditClickListener);

        if (mLyrics == null) {
            if (!startEmpty)
                fetchCurrentLyrics(false);
        } else if (mLyrics.getFlag() == Lyrics.SEARCH_ITEM) {
            mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
            startRefreshAnimation();
            if (mLyrics.getArtist() != null)
                fetchLyrics(mLyrics.getArtist(), mLyrics.getTitle());
            ((TextView) (getActivity().findViewById(R.id.artist))).setText(mLyrics.getArtist());
            ((TextView) (getActivity().findViewById(R.id.song))).setText(mLyrics.getTitle());
        } else //Rotation, resume
            update(mLyrics, layout, false);
    }
    if (broadcastReceiver == null)
        broadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                searchResultLock = false;
                String artist = intent.getStringExtra("artist");
                String track = intent.getStringExtra("track");
                if (artist != null && track != null && mRefreshLayout.isEnabled()) {
                    startRefreshAnimation();
                    new ParseTask(LyricsViewFragment.this, false, true).execute(mLyrics);
                }
            }
        };
    return layout;
}