Example usage for android.widget TextView setText

List of usage examples for android.widget TextView setText

Introduction

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

Prototype

@android.view.RemotableViewMethod
public final void setText(@StringRes int resid) 

Source Link

Document

Sets the text to be displayed using a string resource identifier.

Usage

From source file:com.elkriefy.android.apps.authenticationexample.credentialsgrace.CredGraceActivity.java

private void showAlreadyAuthenticated() {
    TextView textView = (TextView) findViewById(R.id.already_has_valid_device_credential_message);
    textView.setVisibility(View.VISIBLE);
    textView.setText(getString(R.string.already_confirmed_device_credentials_within_last_x_seconds,
            AUTHENTICATION_DURATION_SECONDS));
    findViewById(R.id.purchase_button).setEnabled(false);
}

From source file:net.idlesoft.android.apps.github.activities.CommitChangeViewer.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.commit_view);

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);
    mEditor = mPrefs.edit();// www  .j a v  a2  s .  c  o  m

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(CommitChangeViewer.this, Search.class));
        }
    });

    final TextView title = (TextView) findViewById(R.id.tv_page_title);
    title.setText("Commit Diff");

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mRepositoryName = extras.getString("repo_name");
        mRepositoryOwner = extras.getString("repo_owner");
        try {
            mJson = new JSONObject(extras.getString("json"));

            /*
             * This new method of displaying file diffs was inspired by
             * iOctocat's approach. Thanks to Dennis Bloete (dbloete on
             * GitHub) for creating iOctocat and making me realize Android
             * needed some GitHub love too. ;-)
             */
            final WebView webView = (WebView) findViewById(R.id.wv_commitView_diff);

            /*
             * Prepare CSS for diff: Added lines are green, removed lines
             * are red, and the special lines that specify how many lines
             * were affected in the chunk are a light blue.
             */
            String content = "<style type=\"text/css\">" + "div {" + "margin-right: 100%25;"
                    + "font-family: monospace;" + "white-space: nowrap;" + "display: inline-block;" + "}"
                    + ".lines {" + "background-color: #EAF2F5;" + "}" + ".added {"
                    + "background-color: #DDFFDD;" + "}" + ".removed {" + "background-color: #FFDDDD;" + "}"
                    + "</style>";

            final String[] splitDiff = mJson.getString("diff").split("\n");
            for (int i = 0; i < splitDiff.length; i++) {
                // HTML encode any elements, else any diff containing
                // "<div>" or any HTML element will be interpreted as one by
                // the browser
                splitDiff[i] = TextUtils.htmlEncode(splitDiff[i]);

                // Replace all tabs with four non-breaking spaces (most
                // browsers truncate "\t+" to " ").
                splitDiff[i] = splitDiff[i].replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");

                // Replace any sequence of two or more spaces with &nbsps
                // (most browsers truncate " +" to " ").
                splitDiff[i] = splitDiff[i].replaceAll("(?<= ) ", "&nbsp;");

                if (splitDiff[i].startsWith("@@")) {
                    splitDiff[i] = "<div class=\"lines\">".concat(splitDiff[i].concat("</div>"));
                } else if (splitDiff[i].startsWith("+")) {
                    splitDiff[i] = "<div class=\"added\">".concat(splitDiff[i].concat("</div>"));
                } else if (splitDiff[i].startsWith("-")) {
                    splitDiff[i] = "<div class=\"removed\">".concat(splitDiff[i].concat("</div>"));
                } else {
                    // Add an extra space before lines not beginning with
                    // "+" or "-" to make them line up properly
                    if (splitDiff[i].length() > 0) {
                        splitDiff[i] = "<div>&nbsp;".concat(splitDiff[i].substring(1).concat("</div>"));
                    }
                }
                content += splitDiff[i];
            }
            webView.loadData(content, "text/html", "UTF-8");

        } catch (final JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:net.idlesoft.android.apps.github.activities.DiffFilesList.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.diff_file_list);

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(DiffFilesList.this, Search.class));
        }/*from ww w . ja  va  2  s .c o  m*/
    });

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mRepositoryName = extras.getString("repo_name");
        mRepositoryOwner = extras.getString("repo_owner");
        mType = extras.getString("type");
        try {
            mJson = new JSONObject(extras.getString("json"));
        } catch (final JSONException e) {
            e.printStackTrace();
        }

        try {
            final TextView title = (TextView) findViewById(R.id.tv_page_title);
            if (mType.equals("added")) {
                title.setText("Added Files");
            } else if (mType.equals("removed")) {
                title.setText("Removed Files");
            } else if (mType.equals("modified")) {
                title.setText("Changed Files");
            } else {
                title.setText("Files");
            }

            /*
             * Split JSONArray into a String array so we can populate the
             * list of files
             */
            final String[] filenames = new String[mJson.getJSONArray(mType).length()];
            for (int i = 0; i < filenames.length; i++) {
                if (mType.equals("modified")) {
                    filenames[i] = mJson.getJSONArray("modified").getJSONObject(i).getString("filename");
                } else {
                    filenames[i] = mJson.getJSONArray(mType).getString(i);
                }
                if (filenames[i].lastIndexOf("/") > -1) {
                    filenames[i] = filenames[i].substring(filenames[i].lastIndexOf("/") + 1);
                }
            }

            mAdapter = new ArrayAdapter<String>(DiffFilesList.this, android.R.layout.simple_list_item_1,
                    android.R.id.text1, filenames);

            final ListView file_list = (ListView) findViewById(R.id.lv_diffFileList_list);
            file_list.setAdapter(mAdapter);
            file_list.setOnItemClickListener(mOnFileListItemClick);
        } catch (final JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.mikecorrigan.trainscorekeeper.FragmentButton.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container
            + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState));

    View rootView = inflater.inflate(R.layout.fragment_button, container, false);

    Bundle args = getArguments();/*from  w ww. java 2 s.c  o  m*/
    if (args == null) {
        Log.e(TAG, "onCreateView: missing arguments");
        return rootView;
    }

    // The activity must support a standard OnClickListener.
    final MainActivity mainActivity = (MainActivity) getActivity();
    final Context context = mainActivity;

    players = mainActivity.getPlayers();
    if (players != null) {
        players.addListener(mPlayersListener);
    }

    // final int index = args.getInt(ARG_INDEX);
    final String tabSpec = args.getString(ARG_TAB_SPEC);

    try {
        JSONObject jsonTab = new JSONObject(tabSpec);

        final String tabName = jsonTab.optString(JsonSpec.TAB_NAME, JsonSpec.DEFAULT_TAB_NAME);
        if (!TextUtils.isEmpty(tabName)) {
            TextView tv = (TextView) rootView.findViewById(R.id.text_view_name);
            tv.setText(tabName);
        }

        tabLayout = (LinearLayout) rootView;

        JSONArray jsonSections = jsonTab.getJSONArray(JsonSpec.SECTIONS_KEY);
        for (int i = 0; i < jsonSections.length(); i++) {
            JSONObject jsonSection = jsonSections.getJSONObject(i);

            LinearLayout sectionLayout = new LinearLayout(context);
            sectionLayout.setOrientation(LinearLayout.VERTICAL);
            tabLayout.addView(sectionLayout);

            // If a section is named, label it.
            final String sectionName = jsonSection.optString(JsonSpec.SECTION_NAME,
                    JsonSpec.DEFAULT_SECTION_NAME);
            if (!TextUtils.isEmpty(sectionName)) {
                TextView textView = new TextView(context);
                textView.setText(sectionName);
                sectionLayout.addView(textView);
            }

            int numColumns = jsonSection.optInt(JsonSpec.SECTION_COLUMNS, JsonSpec.DEFAULT_SECTION_COLUMNS);

            List<View> buttonViews = new LinkedList<View>();

            JSONArray buttons = jsonSection.getJSONArray(JsonSpec.BUTTONS_KEY);
            for (int k = 0; k < buttons.length(); k++) {
                JSONObject jsonButton = buttons.getJSONObject(k);

                ScoreButton buttonView = new ScoreButton(context);
                buttonView.setButtonSpec(jsonButton);
                buttonView.setOnClickListener(mainActivity.getScoreClickListener());

                // Add the button to the section.
                buttonViews.add(buttonView);
            }

            GridView gridView = new GridView(context);
            gridView.setNumColumns(numColumns);
            gridView.setAdapter(new ViewAdapter(context, buttonViews));
            sectionLayout.addView(gridView);
        }
    } catch (JSONException e) {
        Log.th(TAG, e, "onCreateView: failed to parse JSON");
    }

    updateUi();

    return rootView;
}

From source file:com.example.savedollars.ProductStockDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    JSONData = (getIntent().getStringExtra("JsonData"));

    if (JSONData != null) {
        parseJsonData(JSONData);/*from  w  ww  .j  a v a2 s .  c om*/
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.pdtstockview);
    // Setting Product Name
    TextView productName = (TextView) findViewById(R.id.pdtNameTextView);
    productName.setText(pdtName);

    Iterator it = sortedMap.keySet().iterator();
    int i = 0;

    System.out.println("3 Updating INFO totalCount:" + totalCount);

    PDT_INFO = new String[totalCount][2];
    while (it.hasNext()) {

        System.out.println("Value of i is " + i);
        String key = ProductTotalPriceDisplay.merchantNames[i];
        System.out.println("smita: merchant keys: " + key);
        String availability = (String) availabilityMap.get(key);

        System.out.println("i = " + i);
        System.out.println("Save DDollars key:" + key);
        System.out.println("Save DDollars availability :" + availability);
        PDT_INFO[i][0] = key;
        PDT_INFO[i][1] = availability;
        System.out.println(
                "While Array Merchant Name:" + PDT_INFO[i][0] + "Array Merchant Price:" + PDT_INFO[i][1]);
        i++;
        it.next();

    }
    System.out.println("Total Updated Rows: " + i + " < totalCount:" + totalCount);

    ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO);

    setListAdapter(listv);
    System.out.println("INFO Updated leter");

}

From source file:com.example.inmarsat.hellomap.MainActivity.java

public void getAccessNetworkRequest() {
    RequestQueue queue = Volley.newRequestQueue(this);
    String url = mAccessNetworkSandboxEndpoint;
    JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override/*from   w w  w . j a v  a2  s  .  c o  m*/
                public void onResponse(JSONObject response) {
                    // response
                    Log.d("Response", response.toString());
                    String accessNetwork;
                    try {
                        accessNetwork = response.getString("accessNetworkName");
                    } catch (Exception e) {
                        return;
                    }
                    if (findViewById(R.id.detailsText) != null) {
                        TextView view = (TextView) findViewById(R.id.detailsText);
                        view.setText("AccessNetwork: " + accessNetwork);
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("ERROR", "error => " + error.toString());
                    if (error.networkResponse != null && error.networkResponse.data != null
                            && findViewById(R.id.detailsText) != null) {
                        TextView view = (TextView) findViewById(R.id.detailsText);
                        view.setText("Error Code: " + error.networkResponse.statusCode);
                    } else if (findViewById(R.id.detailsText) != null) {
                        TextView view = (TextView) findViewById(R.id.detailsText);
                        view.setText(error.toString());
                    }
                }
            }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("Authorization", mAuthorization);

            return params;
        }
    };
    queue.add(getRequest);
}

From source file:com.hybris.mobile.activity.ProductDetailActivity.java

private List<ProductOptionItem> getSelectedOptions() {
    List<ProductOptionItem> result = new ArrayList<ProductOptionItem>();
    Map<String, ProductOptionItem> select = new HashMap<String, ProductOptionItem>();
    for (ProductOptionItem option : mProduct.getAllOptions()) {

        if (option.getVariantOptionQualifiers() != null && !option.getVariantOptionQualifiers().isEmpty()) {
            ProductOptionItem o = new ProductOptionItem();
            o.setName(option.getName());
            o.setQualifier(option.getQualifier());

            if (StringUtils.isNotBlank(o.getName())) {
                o.setValue(getString(R.string.variants_select) + " " + o.getName());
            }//  w ww.j  a v  a2s. c  om

            o.setSelectedOption(true);
            select.put(o.getQualifier(), o);
            if (option.isSelectedOption()) {
                result.add(option);
            }
        }

    }
    for (ProductOptionItem option : result) {
        select.remove(option.getQualifier());
    }
    // Stock level
    TextView stockLevelTextView = (TextView) findViewById(R.id.textViewStockLevel);
    if (select.values().size() > 0) {
        stockLevelTextView.setText(((ProductOptionItem) select.values().toArray()[0]).getValue());
    }

    result.addAll(select.values());
    Collections.sort(result, new Comparator<ProductOptionItem>() {
        @Override
        public int compare(ProductOptionItem lhs, ProductOptionItem rhs) {
            return lhs.getName().compareTo(rhs.getName());
        }
    });
    return result;
}

From source file:net.naonedbus.card.impl.TraficCard.java

private View createView(final LayoutInflater inflater, final ViewGroup root, final InfoTrafic infoTrafic) {
    final View view = inflater.inflate(R.layout.card_item_trafic_ligne, root, false);

    final TextView itemTitle = (TextView) view.findViewById(R.id.itemTitle);
    final TextView itemDate = (TextView) view.findViewById(R.id.itemDate);

    itemTitle.setText(infoTrafic.getIntitule());
    itemDate.setText(infoTrafic.getDateFormated());

    if (isCurrent(infoTrafic)) {
        itemDate.setCompoundDrawablesWithIntrinsicBounds(R.drawable.info_trafic_on, 0, 0, 0);
    } else {/*from w  ww . ja va  2  s  . c  o m*/
        itemDate.setCompoundDrawablesWithIntrinsicBounds(R.drawable.info_trafic_off, 0, 0, 0);
    }

    view.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final Bundle bundle = new Bundle();
            bundle.putParcelable(InfoTraficDetailFragment.PARAM_INFO_TRAFIC, infoTrafic);

            final DialogFragment dialogFragment = new InfoTraficDetailDialogFragment();
            dialogFragment.setArguments(bundle);
            dialogFragment.show(getFragmentManager(), "InfoTraficDetailDialogFragment");
        }
    });

    return view;
}

From source file:net.idlesoft.android.apps.github.activities.FileViewer.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.file_view);/*from ww w  .jav a 2 s  .  c o  m*/

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);
    mEditor = mPrefs.edit();

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(FileViewer.this, Search.class));
        }
    });

    final TextView title = (TextView) findViewById(R.id.tv_page_title);
    title.setText("File Viewer");

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mRepositoryName = extras.getString("repo_name");
        mRepositoryOwner = extras.getString("repo_owner");
        mTreeSha = extras.getString("tree_sha");
        mBlobPath = extras.getString("blob_path");

        mLoadBlobTask = (LoadBlobTask) getLastNonConfigurationInstance();
        if (mLoadBlobTask == null) {
            mLoadBlobTask = new LoadBlobTask();
        }
        mLoadBlobTask.activity = FileViewer.this;
        if (mLoadBlobTask.getStatus() == AsyncTask.Status.RUNNING) {
            mProgressDialog.show();
        } else if (mLoadBlobTask.getStatus() == AsyncTask.Status.PENDING) {
            mLoadBlobTask.execute();
        }
    }
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentWeight.java

private void findViews() {
    Toolbar mToolbar = (Toolbar) v.findViewById(R.id.toolbar_weight);
    TextViewFont txtTitle = (TextViewFont) v.findViewById(R.id.txtTitle);
    txtTitle.setText("Weight");
    mToolbar.inflateMenu(R.menu.menu_weight);
    mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override/* w  ww .ja v  a 2  s.  c o  m*/
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.action_create) {
                FragmentManager fm = getActivity().getSupportFragmentManager();
                UpdateWeightDialogFragment suggestionFragment = new UpdateWeightDialogFragment();
                suggestionFragment.show(fm, "Fragment");
            }
            return false;
        }
    });
    mToolbar.setNavigationIcon(R.mipmap.ic_menu);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCallbacks.openNavigationDrawer();
        }
    });
    weightLogAdapter = new WeightLogAdapter(getActivity(), 0, WeightLog.all());
    listWeight = (ListView) v.findViewById(R.id.listWeight);
    listWeight.setAdapter(weightLogAdapter);
    SetWeightListHeight.setListViewHeight(listWeight);
    WeightLog weightLogStart = weightLogAdapter.getItem(0);
    TextView startWeight = (TextView) v.findViewById(R.id.startWeight);
    startWeight.setText(df.format(weightLogStart.getCurrentWeight()) + " lbs");
    WeightLog weightLogCurrent = weightLogAdapter.getItem(weightLogAdapter.getCount() - 1);
    TextView currentWeight = (TextView) v.findViewById(R.id.currentWeight);
    currentWeight.setText(df.format(weightLogCurrent.getCurrentWeight()) + " lbs");
    double totalWeightLoss = weightLogStart.getCurrentWeight() - weightLogCurrent.getCurrentWeight();
    TextView lossWeight = (TextView) v.findViewById(R.id.lossWeight);
    lossWeight.setText(df.format(totalWeightLoss) + " lbs");
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    TextView goalWeight = (TextView) v.findViewById(R.id.goalWeight);
    goalWeight.setText(sharedPreferences.getString(Globals.USER_WEIGHT_GOAL, "") + " lbs");
    double weightRemaining = weightLogCurrent.getCurrentWeight()
            - Double.valueOf(sharedPreferences.getString(Globals.USER_WEIGHT_GOAL, ""));
    TextView remainderWeight = (TextView) v.findViewById(R.id.remainderWeight);
    remainderWeight.setText(df.format(weightRemaining) + " lbs");
    max = (int) Precision.round(weightLogStart.getCurrentWeight(), -1) + 10;
    if (Double.valueOf(sharedPreferences.getString(Globals.USER_WEIGHT_GOAL, "")) < weightLogCurrent
            .getCurrentWeight()) {
        min = (int) Precision.round(Integer.valueOf(sharedPreferences.getString(Globals.USER_WEIGHT_GOAL, "")),
                -1) - 10;
    } else {
        min = (int) Precision.round(weightLogCurrent.getCurrentWeight(), -1) - 10;
    }
    goalWeightLine = Float.valueOf(sharedPreferences.getString(Globals.USER_WEIGHT_GOAL, ""));

    goalPosition = Integer.valueOf(sharedPreferences.getString(Globals.USER_WEIGHT_LOSS_GOAL, ""));
    if (goalPosition == 0 || goalPosition == 8) {
        weightPerWeek = 2;
    }
    if (goalPosition == 1 || goalPosition == 7) {
        weightPerWeek = 1.5;
    }
    if (goalPosition == 2 || goalPosition == 6) {
        weightPerWeek = 1;
    }
    if (goalPosition == 3 || goalPosition == 5) {
        weightPerWeek = .5;
    }
    if (goalPosition == 4) {
        weightPerWeek = 0;
    }
    timeTillGoal = weightRemaining / weightPerWeek;

    TextView timeRem = (TextView) v.findViewById(R.id.timeRem);
    timeRem.setText(df.format(timeTillGoal) + " Week(s)");
}