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:edu.stanford.mobisocial.dungbeetle.GroupsActivity.java

public void setTitleFromActivityLabel(int textViewId) {
    TextView tv = (TextView) findViewById(textViewId);
    if (tv != null)
        tv.setText(getTitle());
}

From source file:com.linkedin.android.eventsapp.AttendeeAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.attendee_list_item, parent, false);
    TextView attendeeNameView = (TextView) rowView.findViewById(R.id.attendeeName);
    final TextView attendeeHeadlineView = (TextView) rowView.findViewById(R.id.attendeeHeadline);
    final ImageView attendeeImageView = (ImageView) rowView.findViewById(R.id.attendeeImage);

    Person attendee = attendees[position];
    attendeeNameView.setText(attendee.getFirstName() + " " + attendee.getLastName());

    boolean isAccessTokenValid = LISessionManager.getInstance(context).getSession().isValid();
    if (isAccessTokenValid) {
        String url = Constants.personByIdBaseUrl + attendee.getLinkedinId() + Constants.personProjection;
        //LISession liSession = LISessionManager.getInstance(context).getSession()
        APIHelper.getInstance(context).getRequest(context, url, new ApiListener() {
            @Override/*from w  w w .j  a  v a2s  . co m*/
            public void onApiSuccess(ApiResponse apiResponse) {
                try {
                    JSONObject dataAsJson = apiResponse.getResponseDataAsJson();
                    String headline = dataAsJson.has("headline") ? dataAsJson.getString("headline") : "";
                    String pictureUrl = dataAsJson.has("pictureUrl") ? dataAsJson.getString("pictureUrl")
                            : null;
                    JSONObject location = dataAsJson.getJSONObject("location");

                    attendeeHeadlineView.setText(headline);
                    if (pictureUrl != null) {
                        new com.linkedin.android.eventsapp.FetchImageTask(attendeeImageView)
                                .execute(pictureUrl);
                    } else {
                        attendeeImageView.setImageResource(R.drawable.ghost_person);
                    }
                } catch (JSONException e) {

                }

            }

            @Override
            public void onApiError(LIApiError apiError) {

            }
        });
    } else {
        attendeeImageView.setImageResource(R.drawable.ghost_person);
    }

    return rowView;
}

From source file:com.github.wakhub.monodict.activity.settings.DownloadsActivity.java

@AfterViews
void afterViews() {
    commonActivityTrait.initActivity(preferences);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    sdCard = Environment.getExternalStorageDirectory();

    resultIntent = getIntent();//from  www.  ja v  a 2s.c  o  m
    dlTask = new DownloadTask();

    listAdapter = new ArrayAdapter<DownloadsItem>(this, android.R.layout.simple_list_item_2,
            android.R.id.text1) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            DownloadsItem item = getItem(position);

            TextView text1 = (TextView) view.findViewById(android.R.id.text1);
            text1.setText(Dictionary.EMOJI + item.getName());

            TextView text2 = (TextView) view.findViewById(android.R.id.text2);
            text2.setText(String.format("%s\nsize: %s", item.getDescription(), item.getSize()));

            return view;
        }
    };
    setListAdapter(listAdapter);

    Downloads downloads = null;
    try {
        InputStream inputStream = getAssets().open("downloads.json");
        downloads = (new Gson()).fromJson(IOUtils.toString(inputStream), Downloads.class);
    } catch (IOException e) {
        activityHelper.showError(e);
        return;
    }
    listAdapter.addAll(downloads.getItems());
}

From source file:com.naman14.algovisualizer.AlgoDescriptionFragment.java

private void addDescData(String algorithmKey) {
    if (descJson == null || descObject == null || getActivity() == null) {
        return;//from w ww  . j  av a2  s .  c  o m
    }
    rootView.removeAllViews();
    try {
        JSONObject dataObject = descObject.getJSONObject(algorithmKey);

        Iterator<?> keys = dataObject.keys();

        while (keys.hasNext()) {

            View descView = LayoutInflater.from(getActivity()).inflate(R.layout.item_code_desc, rootView,
                    false);
            TextView title = (TextView) descView.findViewById(R.id.title);
            TextView desc = (TextView) descView.findViewById(R.id.desc);
            desc.setMovementMethod(LinkMovementMethod.getInstance());

            String key = (String) keys.next();
            title.setText(key);

            if (dataObject.get(key) instanceof JSONObject) {
                JSONObject jsonObject = dataObject.getJSONObject(key);
                String descString = "";

                Iterator<?> complexityKeys = jsonObject.keys();

                while (complexityKeys.hasNext()) {
                    String complexityKey = (String) complexityKeys.next();
                    descString += " - ";
                    descString += complexityKey;
                    descString += " : ";
                    descString += jsonObject.getString(complexityKey);
                    descString += "<br>";
                }
                desc.setText(Html.fromHtml(descString));

            } else if (dataObject.get(key) instanceof JSONArray) {
                JSONArray array = dataObject.getJSONArray(key);
                String descString = "";

                for (int i = 0; i < array.length(); i++) {
                    descString += " - ";
                    descString += array.getString(i);
                    descString += "<br>";
                }
                desc.setText(Html.fromHtml(descString));

            } else if (dataObject.get(key) instanceof String) {
                desc.setText(Html.fromHtml(dataObject.getString(key)));
            }

            rootView.addView(descView);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:gov.wa.wsdot.android.wsdot.ui.SeattleTrafficAlertsFragment.java

public void onLoadFinished(Loader<ArrayList<SeattleIncidentItem>> loader, ArrayList<SeattleIncidentItem> data) {

    if (!data.isEmpty()) {
        mAdapter.setData(data);//from  w  w w .  j  a  va  2s .c om
    } else {
        TextView t = (TextView) mEmptyView;
        t.setText(R.string.no_connection);
        getListView().setEmptyView(mEmptyView);
    }

    swipeRefreshLayout.setRefreshing(false);
}

From source file:com.justinbull.ichnaeachecker.MainActivity.java

public RequestHandle getIchnaeaLookup(final Snackbar snack) {
    Log.i(TAG, "getIchnaeaLookup: Looking up " + mSelectedCell);
    return IchnaeaRestClient.geolocate(mSelectedCell, new JsonHttpResponseHandler() {
        @Override/* w  ww. jav  a 2  s. c o m*/
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                Log.i(TAG, "onSuccess: Cell in database! Location is: " + response.get("location") + " for "
                        + mSelectedCell);
                TextView text = (TextView) findViewById(R.id.topLevelText);
                assert text != null;
                text.setText("Cell " + mSelectedCell.getFriendlyCellIdentity() + " in database!");
                TextView textLat = (TextView) findViewById(R.id.latitudeText);
                TextView textLng = (TextView) findViewById(R.id.longitudeText);
                TextView textAcurracy = (TextView) findViewById(R.id.accuracyText);
                assert textLat != null;
                assert textLng != null;
                assert textAcurracy != null;
                textLat.setText(
                        "Latitude: " + Double.toString(response.getJSONObject("location").getDouble("lat")));
                textLng.setText(
                        "Longitude: " + Double.toString(response.getJSONObject("location").getDouble("lng")));
                textAcurracy
                        .setText("Accuracy: " + Double.toString(response.getDouble("accuracy")) + " meters");
                textLat.setVisibility(View.VISIBLE);
                textLng.setVisibility(View.VISIBLE);
                textAcurracy.setVisibility(View.VISIBLE);
                Snackbar snackSuccess = Snackbar.make(
                        snack.getView(), mSelectedCell.getCellType() + " Cell "
                                + mSelectedCell.getFriendlyCellIdentity() + " in Ichnaea database!",
                        Snackbar.LENGTH_LONG);
                snackSuccess.getView()
                        .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorSuccess));
                snackSuccess.show();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            try {
                if (statusCode == 404 && errorResponse.getJSONObject("error").getInt("code") == 404) {
                    Log.i(TAG, "onFailure: Cell is not in database: " + mSelectedCell);
                    TextView text = (TextView) findViewById(R.id.topLevelText);
                    assert text != null;
                    text.setText("NOT IN DATABASE!");
                    TextView textLat = (TextView) findViewById(R.id.latitudeText);
                    TextView textLng = (TextView) findViewById(R.id.longitudeText);
                    TextView textAcurracy = (TextView) findViewById(R.id.accuracyText);
                    textLat.setVisibility(View.INVISIBLE);
                    textLng.setVisibility(View.INVISIBLE);
                    textAcurracy.setVisibility(View.INVISIBLE);
                } else {
                    Toast.makeText(MainActivity.this, "Unknown error occurred", Toast.LENGTH_SHORT).show();
                }
            } catch (JSONException e) {
                Toast.makeText(MainActivity.this, "Unknown error occurred", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
            snack.dismiss();
        }

        @Override
        public void onCancel() {
            super.onCancel();
            snack.dismiss();
        }
    });
}

From source file:kr.co.generic.wifianalyzer.wifi.AccessPointDetail.java

private void setViewVendorLong(@NonNull View view, @NonNull WiFiAdditional wiFiAdditional) {
    TextView textVendor = ((TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.vendorLong));
    String vendor = wiFiAdditional.getVendorName();
    if (StringUtils.isBlank(vendor)) {
        textVendor.setVisibility(View.GONE);
    } else {//from   w  w  w.  j  ava2  s. c  om
        textVendor.setVisibility(View.VISIBLE);
        textVendor.setText(vendor.substring(0, Math.min(VENDOR_LONG_MAX, vendor.length())));
    }
}

From source file:com.brodev.socialapp.view.MusicPlaySong.java

/** This method initialise all the views in project */
private void initView() {
    buttonPlayPause = (ImageButton) findViewById(R.id.buttonPlayPause);
    buttonPlayPause.setOnClickListener(this);

    seekBarProgress = (SeekBar) findViewById(R.id.SeekBarTestPlay);
    seekBarProgress.setMax(99); // It means 100% .0-99
    seekBarProgress.setOnTouchListener(this);

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setOnBufferingUpdateListener(this);
    mediaPlayer.setOnCompletionListener(this);

    try {/*  w w  w . j a v a 2s . c  o m*/
        mediaPlayer.setDataSource(music.getSong_path()); // setup song from
        // http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3
        // URL to
        // mediaplayer
        // data source
        mediaPlayer.prepareAsync(); // you must call this method after setup
        // the datasource in setDataSource
        // method. After calling prepare() the
        // instance of MediaPlayer starts load
        // data from URL to internal buffer.
    } catch (Exception e) {
        e.printStackTrace();
    }

    mediaFileLengthInMilliseconds = mediaPlayer.getDuration(); // gets the
    // song
    // length in
    // milliseconds
    // from URL

    // set song name
    TextView songName = (TextView) findViewById(R.id.songName);
    songName.setText(music.getTitle());
    colorView.changeColorText(songName, user.getColor());

    // set short text
    TextView shortText = (TextView) findViewById(R.id.shortText);
    shortText.setText(music.getShort_text());

    TextView time_stamp = (TextView) findViewById(R.id.time_stamp);
    time_stamp.setText(music.getTime_stamp());
    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(music.getTotal_like());
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(music.getTotal_comment());
    colorView.changeColorText(total_comment, user.getColor());

    ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt);
    ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt);
    colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor());

    // set User image
    ImageView userImage = (ImageView) findViewById(R.id.image_user);
    networkUntil.drawImageUrl(userImage, music.getUser_image_path(), R.drawable.loading);
    userImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MusicPlaySong.this, FriendTabsPager.class);
            intent.putExtra("user_id", music.getUser_id());
            startActivity(intent);
            return false;
        }
    });

}

From source file:asu.edu.msse.gpeddabu.moviedescriptions.MovieListAdapter.java

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    String headerTitle = (String) getGroup(groupPosition);
    if (convertView == null) {
        android.util.Log.d(this.getClass().getSimpleName(), "in getGroupView null so creating new view");
        LayoutInflater inflater = (LayoutInflater) this.parent
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.movie_group, null);
    }//from  www.  j a v  a2  s  .  c  om

    TextView genreName = (TextView) convertView.findViewById(R.id.genreName);
    //android.util.Log.d(this.getClass().getSimpleName(),"in getGroupView text is: "+lblListHeader.getText());
    genreName.setTypeface(null, Typeface.BOLD);
    genreName.setText(headerTitle);
    return convertView;
}