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:gov.in.bloomington.georeporter.fragments.SavedReportViewFragment.java

private void refreshViewData() {
    View v = getView();/*  ww  w  .j  a  va2 s .c o  m*/
    TextView textView;

    textView = (TextView) v.findViewById(R.id.service_name);
    textView.setText(mServiceRequest.service.optString(Open311.SERVICE_NAME));

    ImageView media = (ImageView) v.findViewById(R.id.media);
    media.setImageBitmap(mServiceRequest.getMediaBitmap(100, 100, getActivity()));

    textView = (TextView) v.findViewById(R.id.address);
    if (mServiceRequest.service_request.has(Open311.ADDRESS)) {
        textView.setText(mServiceRequest.service_request.optString(Open311.ADDRESS));
    } else if (mServiceRequest.post_data.has(Open311.ADDRESS_STRING)) {
        textView.setText(mServiceRequest.post_data.optString(Open311.ADDRESS_STRING));
    }

    textView = (TextView) v.findViewById(R.id.description);
    if (mServiceRequest.service_request.has(Open311.DESCRIPTION)) {
        textView.setText(mServiceRequest.service_request.optString(Open311.DESCRIPTION));
    } else if (mServiceRequest.post_data.has(Open311.DESCRIPTION)) {
        textView.setText(mServiceRequest.post_data.optString(Open311.DESCRIPTION));
    }

    textView = (TextView) v.findViewById(R.id.status);
    if (mServiceRequest.service_request.has(ServiceRequest.STATUS)) {
        textView.setText(mServiceRequest.service_request.optString(ServiceRequest.STATUS));
    }
}

From source file:com.github.naofum.gogakudroid.AsyncDownload.java

@Override
protected void onPostExecute(String result) {
    if (progressDialog != null && progressDialog.isShowing()) {
        try {// ww  w  .  j  a va2s. c  o  m
            progressDialog.dismiss();
        } catch (Exception e) {
            //
        }
    }

    TextView textView1 = (TextView) owner.findViewById(R.id.textView1);
    textView1.setText(lastMessage);
    Toast.makeText(owner, lastMessage, Toast.LENGTH_LONG).show();
}

From source file:com.partypoker.poker.engagement.reach.activity.EngagementPollActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    /* Init layout */
    super.onCreate(savedInstanceState);

    /* If no content, nothing to do, super class already called finish */
    if (mContent == null)
        return;// w w  w.ja v  a2 s.  co  m

    /* Render questions */
    LinearLayout questionsLayout = getView("questions");
    JSONArray questions = mContent.getQuestions();
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    try {
        for (int i = 0; i < questions.length(); i++) {
            /* Get question */
            JSONObject question = questions.getJSONObject(i);

            /* Inflate question layout */
            LinearLayout questionLayout = (LinearLayout) layoutInflater
                    .inflate(getLayoutId("engagement_poll_question"), null);

            /* Set question's title */
            TextView questionTitle = (TextView) questionLayout.findViewById(getId("question_title"));
            questionTitle.setText(question.getString("title"));

            /* Set choices */
            RadioGroup choicesView = (RadioGroup) questionLayout.findViewById(getId("choices"));
            choicesView.setTag(question);
            JSONArray choices = question.getJSONArray("choices");
            int choiceViewId = 0;
            for (int j = 0; j < choices.length(); j++) {
                /* Get choice */
                JSONObject choice = choices.getJSONObject(j);

                /* Inflate choice layout */
                RadioButton choiceView = (RadioButton) layoutInflater
                        .inflate(getLayoutId("engagement_poll_choice"), null);

                /* Each choice is a radio button */
                choiceView.setId(choiceViewId++);
                choiceView.setTag(choice.getString("id"));
                choiceView.setText(choice.getString("title"));
                choiceView.setChecked(choice.optBoolean("isDefault"));
                choicesView.addView(choiceView);
            }

            /* Add to parent layouts */
            questionsLayout.addView(questionLayout);

            /* Watch state */
            mRadioGroups.add(choicesView);
            choicesView.setOnCheckedChangeListener(mRadioGroupListener);
        }
    } catch (JSONException jsone) {
        /* Drop on parsing error */
        mContent.dropContent(this);
        finish();
        return;
    }

    /* Disable action if a choice is not selected */
    updateActionState();
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    JSONData = (getIntent().getStringExtra("JsonData"));
    System.out.println("Json data in price page: " + JSONData);
    if (JSONData != null) {
        parseJsonData(JSONData);//from  ww  w .j  av a  2 s.  c  o m
    }
    super.onCreate(savedInstanceState);
    System.out.println("after on create");

    setContentView(R.layout.pdtpriceview);

    //Setting Product Name
    TextView productName = (TextView) findViewById(R.id.pdtNameTextView);
    productName.setText(pdtName);

    Iterator objMapIterator = sortedMap.entrySet().iterator();
    int i = 0;
    System.out.println("3 Updating INFO totalCount:" + totalCount);

    PDT_INFO = new String[totalCount][2];
    while (objMapIterator.hasNext()) {
        Map.Entry keyValuePairs = (Map.Entry) objMapIterator.next();
        String key = ProductTotalPriceDisplay.merchantNames[i];

        PDT_INFO[i][0] = key;
        PDT_INFO[i][1] = "$" + sortedMap.get(key);
        System.out.println(
                "While Array Merchant Name:" + PDT_INFO[i][0] + "Array Merchant Price:" + PDT_INFO[i][1]);
        i++;
    }
    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.springsource.greenhouse.events.sessions.EventSessionDetailsActivity.java

private void setFavoriteStatus(Boolean status) {
    final TextView textViewSessionFavorite = (TextView) findViewById(R.id.event_session_details_favorite);
    String text = status ? "Favorite: \u2713" : "Not a Favorite";
    textViewSessionFavorite.setText(text);
}

From source file:org.mifos.androidclient.util.listadapters.SimpleExpandableListAdapter.java

@Override
public View getChildView(int groupPos, int childPos, boolean isLastChild, View convertView, ViewGroup parent) {
    View row;//from ww w .  j av  a  2  s  . co m
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.simple_list_child, parent, false);
    } else {
        row = convertView;
    }
    SimpleListItem item = (SimpleListItem) getChild(groupPos, childPos);
    if (item != null) {
        TextView label = (TextView) row.findViewById(R.id.simple_list_item_label);
        label.setText(item.getListLabel());
    }
    return row;
}

From source file:com.handlerexploit.news.fragments.WeatherFragment.java

private void render(WeatherInfo weatherInfo) {
    Activity activity = getActivity();//w  ww.ja  va  2 s .  com
    if (activity != null && weatherInfo != null) {
        View root = getView();

        TextView city = (TextView) root.findViewById(R.id.city);
        city.setText(weatherInfo.getCity());

        CurrentWeather currentWeather = weatherInfo.getCurrentWeather();

        RemoteImageView icon = (RemoteImageView) root.findViewById(R.id.icon);
        int resId = activity.getResources().getIdentifier(currentWeather.getIcon(), "drawable",
                activity.getPackageName());
        if (resId != 0) {
            ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(resId);
            icon.setImageResource(resId);
        } else {
            ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(R.drawable.unknown);
            icon.setImageResource(R.drawable.unknown);
        }

        TextView temp = (TextView) root.findViewById(R.id.temp);
        temp.setText(currentWeather.getTempF() + " \u00B0F | " + currentWeather.getTempC() + " \u00B0C");
        ((TextView) activity.findViewById(R.id.weather_small_text))
                .setText(currentWeather.getTempF() + "\u00B0");

        TextView condition = (TextView) root.findViewById(R.id.condition);
        String conditionText = currentWeather.getCondition();
        if (conditionText != null && !conditionText.equals("")) {
            condition.setText(conditionText);
        } else {
            condition.setText("N/A");
        }

        TextView windCondition = (TextView) root.findViewById(R.id.windCondition);
        windCondition.setText(currentWeather.getWindCondition());

        TextView humidity = (TextView) root.findViewById(R.id.humidity);
        humidity.setText(currentWeather.getHumidity());

        LinearLayout forcastConditions = (LinearLayout) root.findViewById(R.id.forcastConditions);
        forcastConditions.removeAllViews();

        LayoutInflater inflater = LayoutInflater.from(activity);
        LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        params.weight = 1f;

        ArrayList<Condition> forcastArray = weatherInfo.getForcastConditions();
        for (int i = 0; i < forcastArray.size(); i++) {
            Condition forcastCondition = forcastArray.get(i);
            View forcastRoot = inflater.inflate(R.layout.fragment_weather_condition_item, null);

            TextView forcastDay = (TextView) forcastRoot.findViewById(R.id.day);
            forcastDay.setText(forcastCondition.getDay());

            RemoteImageView forcastIcon = (RemoteImageView) forcastRoot.findViewById(R.id.icon);
            int forcastResId = activity.getResources().getIdentifier(forcastCondition.getIcon(), "drawable",
                    activity.getPackageName());
            if (forcastResId != 0) {
                forcastIcon.setImageResource(forcastResId);
            } else {
                forcastIcon.setImageResource(R.drawable.unknown);
            }

            TextView forcastHigh = (TextView) forcastRoot.findViewById(R.id.high);
            forcastHigh.setText(forcastCondition.getHigh() + "\u00B0");

            TextView forcastLow = (TextView) forcastRoot.findViewById(R.id.low);
            forcastLow.setText(forcastCondition.getLow() + "\u00B0");

            forcastConditions.addView(forcastRoot, params);
        }
    }
}

From source file:dk.moerks.ratebeermobile.Rate.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rate);//w ww . ja  v a 2s.c  o  m

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        beername = extras.getString("BEERNAME");
        beerid = extras.getString("BEERID");
    }

    rateCharleftText = (TextView) findViewById(R.id.rate_label_charleft);
    rateCharleftText.setText(getText(R.string.rate_charleft) + " 75");
    EditText rateComment = (EditText) findViewById(R.id.rate_value_comments);
    rateComment.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            int charNumber = s.length();
            int resultNumber = 75 - charNumber;
            if (resultNumber > 0) {
                rateCharleftText.setText(getText(R.string.rate_charleft) + " " + resultNumber);
            } else {
                rateCharleftText.setText("");
            }
        }
    });

    TextView beernameText = (TextView) findViewById(R.id.rate_label_beername);
    beernameText.setText(beername);

    Button rateButton = (Button) findViewById(R.id.rate_button);
    rateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            EditText comment = (EditText) findViewById(R.id.rate_value_comments);
            final String commentString = comment.getText().toString();

            if (commentString.length() > 74) {

                Spinner aromaText = (Spinner) findViewById(R.id.rate_value_aroma);
                Spinner appearanceText = (Spinner) findViewById(R.id.rate_value_appearance);
                Spinner flavorText = (Spinner) findViewById(R.id.rate_value_flavor);
                Spinner palateText = (Spinner) findViewById(R.id.rate_value_palate);
                Spinner overallText = (Spinner) findViewById(R.id.rate_value_overall);

                final String aromaString = (String) aromaText.getSelectedItem();
                final String appearanceString = (String) appearanceText.getSelectedItem();
                final String flavorString = (String) flavorText.getSelectedItem();
                final String palateString = (String) palateText.getSelectedItem();
                final String overallString = (String) overallText.getSelectedItem();
                String totalScore = calculateTotalScore(aromaString, appearanceString, flavorString,
                        palateString, overallString);

                List<NameValuePair> parameters = new ArrayList<NameValuePair>();
                parameters.add(new BasicNameValuePair("BeerID", beerid));
                parameters.add(new BasicNameValuePair("aroma", aromaString));
                parameters.add(new BasicNameValuePair("appearance", appearanceString));
                parameters.add(new BasicNameValuePair("flavor", flavorString));
                parameters.add(new BasicNameValuePair("palate", palateString));
                parameters.add(new BasicNameValuePair("overall", overallString));
                parameters.add(new BasicNameValuePair("totalscore", totalScore));
                parameters.add(new BasicNameValuePair("Comments", commentString));

                new SaveRatingTask(Rate.this).execute(parameters.toArray(new NameValuePair[] {}));

                SharedPreferences prefs = getSharedPreferences(Settings.PREFERENCETAG, 0);
                if (prefs.getBoolean("rb_twitter_ratings", false)) {
                    new PostTwitterStatusTask(Rate.this).execute(buildTwitterMessage(totalScore));
                }

                finish();

            } else {
                Toast.makeText(Rate.this, R.string.toast_minimum_length, Toast.LENGTH_LONG).show();
            }
        }

        private String buildTwitterMessage(String score) {
            return getString(R.string.twitter_rating_message, beername, score, getUserId());
        }

        private String calculateTotalScore(String aromaString, String appearanceString, String flavorString,
                String palateString, String overallString) {
            int aroma = Integer.parseInt(aromaString);
            int appearance = Integer.parseInt(appearanceString);
            int flavor = Integer.parseInt(flavorString);
            int palate = Integer.parseInt(palateString);
            int overall = Integer.parseInt(overallString);

            int total = (aroma + appearance + flavor + palate + overall);

            float totalscore = ((float) total) / 10;
            String result = "" + totalscore;
            return result;
        }
    });
}

From source file:com.example.android.wearable.wear.wearoauth.WearOAuthActivity.java

/**
 * Helper method to update display with fetched results on the activity view.
 *
 * @param text Returned text to display/*w  ww .  j  av a  2s . c  o m*/
 */
private void updateStatus(final String text) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            TextView textView = (TextView) findViewById(text_view);
            Log.d(TAG, text);
            textView.setText(text);
        }
    });
}

From source file:com.radicaldynamic.groupinform.application.Collect.java

public void showCustomToast(String message) {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.toast_view, null);

    // Set the text in the view
    TextView tv = (TextView) view.findViewById(R.id.message);
    tv.setText(message);

    Toast t = new Toast(this);
    t.setView(view);/*from  w ww  .java2 s . com*/
    t.setDuration(Toast.LENGTH_SHORT);
    t.setGravity(Gravity.CENTER, 0, 0);
    t.show();
}