Java Code Examples for android.widget.TextView#setText()

The following examples show how to use android.widget.TextView#setText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BindingAdapters.java    From EasyNLU with Apache License 2.0 6 votes vote down vote up
@BindingAdapter("textRepeat")
public static void textRepeat(TextView view, long repeatDuration){
    if(repeatDuration != -1){
        final long[] duration = {0};
        final String[] unit = {""};

        zip(KEYS_MUL, KEYS_TIME)
            .forEach((mul, time) ->{
                if(repeatDuration % mul == 0){
                    duration[0] = repeatDuration / mul;
                    unit[0] = time;
                    return false;
                }

                return true;
            });

        if(duration[0] > 0){
            if(duration[0] == 1)
                view.setText(String.format("Every %s", unit[0]));
            else
                view.setText(String.format("Every %d %ss", (int)duration[0], unit[0]));
        }
    }
}
 
Example 2
Source File: SubmitOrderActivity.java    From HomeApplianceMall with MIT License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = LayoutInflater.from(context).inflate(R.layout.item_a_order_submit,null);
    ImageView imageView = (ImageView) v.findViewById(R.id.imageView_i_a_order_img);
    TextView textName = (TextView) v.findViewById(R.id.textView_i_a_order_submit_name);
    TextView textNumber = (TextView) v.findViewById(R.id.textView_i_a_order_submit_number);
    TextView textPrice = (TextView) v.findViewById(R.id.textView_i_a_order_submit_price);
    imageView.setImageResource((int)list.get(position).get("img"));
    textName.setText((String)list.get(position).get("name"));
    textNumber.setText((String)list.get(position).get("number"));
    textPrice.setText((String)list.get(position).get("price"));
    if(!list.get(position).containsKey("imgPath") || list.get(position).get("imgPath")==null){
        imageView.setImageResource(R.drawable.wait);
    }else{
        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 3;
        imageView.setImageBitmap(BitmapFactory.decodeFile((String)list.get(position).get("imgPath"),options));
    }
    return v;
}
 
Example 3
Source File: ImageCardItem.java    From StackCardsView with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(View convertView, ViewGroup parent) {
    convertView = View.inflate(mContext,R.layout.item_imagecard,null);
    ImageView imageView = Utils.findViewById(convertView,R.id.image);
    TextView labelview = Utils.findViewById(convertView,R.id.label);
    ImageView left = Utils.findViewById(convertView,R.id.left);
    ImageView right = Utils.findViewById(convertView,R.id.right);
    ImageView up = Utils.findViewById(convertView,R.id.up);
    ImageView down = Utils.findViewById(convertView,R.id.down);
    ViewHolder vh = new ViewHolder();
    vh.left = left;
    vh.right = right;
    vh.up = up;
    vh.down = down;
    convertView.setTag(vh);
    Glide.with(mContext)
            .load(url)
            .placeholder(R.drawable.img_dft)
            .centerCrop()
            .crossFade()
            .into(imageView);
    labelview.setText(label);
    return convertView;
}
 
Example 4
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 6 votes vote down vote up
private void createTimer(final long milliseconds) {
    // Create the game timer, which counts down to the end of the level
    // and shows the "retry" button.
    if (countDownTimer != null) {
        countDownTimer.cancel();
    }

    final TextView textView = findViewById(R.id.timer);

    countDownTimer = new CountDownTimer(milliseconds, 50) {
        @Override
        public void onTick(long millisUnitFinished) {
            timerMilliseconds = millisUnitFinished;
            textView.setText("seconds remaining: " + ((millisUnitFinished / 1000) + 1));
        }

        @Override
        public void onFinish() {
            gameIsInProgress = false;
            textView.setText("done!");
            retryButton.setVisibility(View.VISIBLE);
        }
    };
}
 
Example 5
Source File: HugoActivity.java    From hugo with Apache License 2.0 6 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  TextView tv = new TextView(this);
  tv.setText("Check logcat!");
  setContentView(tv);

  printArgs("The", "Quick", "Brown", "Fox");

  Log.i("Fibonacci", "fibonacci's 4th number is " + fibonacci(4));

  Greeter greeter = new Greeter("Jake");
  Log.d("Greeting", greeter.sayHello());

  Charmer charmer = new Charmer("Jake");
  Log.d("Charming", charmer.askHowAreYou());

  startSleepyThread();
}
 
Example 6
Source File: StepCountAdapter.java    From BackPackTrackII with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    long time = cursor.getLong(colTime);
    int count = cursor.getInt(colCount);

    // Get views
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvCount = (TextView) view.findViewById(R.id.tvCount);
    TextView tvDistance = (TextView) view.findViewById(R.id.tvDistance);
    TextView tvCalories = (TextView) view.findViewById(R.id.tvCalories);

    // Calculations
    float distance = count * stepsize / 100f;
    float calories = (distance / 1000f / 1.609344f) * (weight / 0.45359237f) * 0.3f;
    // http://www.runnersworld.com/weight-loss/how-many-calories-are-you-really-burning

    // Set values
    float zone = (time % (24 * 3600 * 1000L)) / (float) (3600 * 1000);
    zone = (zone <= 12 ? 0 : 24) - zone;
    tvTime.setText(SDF.format(time + 12 * 3600 * 1000L) + ZF.format(zone));
    tvCount.setText(Long.toString(count));
    tvDistance.setText(Long.toString(Math.round(distance)));
    tvCalories.setText(Long.toString(Math.round(calories)));
}
 
Example 7
Source File: MainActivity.java    From PLDroidMediaStreaming with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView versionInfo = (TextView) findViewById(R.id.version_info);
    mInputTextTV = (TextView) findViewById(R.id.input_url);
    mInputTypeSpinner = (Spinner) findViewById(R.id.stream_input_types);
    mStreamTypeSpinner = (Spinner) findViewById(R.id.stream_types);
    mDebugModeCheckBox = (CheckBox) findViewById(R.id.debug_mode);
    mQuicPushButton = (RadioButton) findViewById(R.id.transfer_quic);

    mInputTextTV.setText(Cache.retrieveURL(this));

    FragmentManager fragmentManager = getSupportFragmentManager();
    mEncodingConfigFragment = (EncodingConfigFragment) fragmentManager.findFragmentById(R.id.encoding_config_fragment);
    mCameraConfigFragment = (CameraConfigFragment) fragmentManager.findFragmentById(R.id.camera_config_fragment);

    versionInfo.setText("versionName: " + BuildConfig.VERSION_NAME + " versionCode: " + BuildConfig.VERSION_CODE);
    initInputTypeSpinner();
    initStreamTypeSpinner();
}
 
Example 8
Source File: BGANormalRefreshViewHolder.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
@Override
public View getRefreshHeaderView() {
    if (mRefreshHeaderView == null) {
        mRefreshHeaderView = View.inflate(mContext, R.layout.view_refresh_header_normal, null);
        mRefreshHeaderView.setBackgroundColor(Color.TRANSPARENT);
        if (mRefreshViewBackgroundColorRes != -1) {
            mRefreshHeaderView.setBackgroundResource(mRefreshViewBackgroundColorRes);
        }
        if (mRefreshViewBackgroundDrawableRes != -1) {
            mRefreshHeaderView.setBackgroundResource(mRefreshViewBackgroundDrawableRes);
        }
        mHeaderStatusTv = (TextView) mRefreshHeaderView.findViewById(R.id.tv_normal_refresh_header_status);
        mHeaderArrowIv = (ImageView) mRefreshHeaderView.findViewById(R.id.iv_normal_refresh_header_arrow);
        mHeaderChrysanthemumIv = (ImageView) mRefreshHeaderView.findViewById(R.id.iv_normal_refresh_header_chrysanthemum);
        mHeaderChrysanthemumAd = (AnimationDrawable) mHeaderChrysanthemumIv.getDrawable();
        mHeaderStatusTv.setText(mPullDownRefreshText);
    }
    return mRefreshHeaderView;
}
 
Example 9
Source File: TabLayout.java    From SimpleProject with MIT License 5 votes vote down vote up
public void setItemData(int[] textColor, String[] tabText, int[] normalIconIds, int[] selectedIconIds) {
	if (tabText == null || normalIconIds == null || selectedIconIds == null) {
		throw new NullPointerException("tabText or selectedIconId or unselectedIconId is null");
	} else if (tabText.length == 0 || tabText.length != normalIconIds.length
			|| selectedIconIds.length != normalIconIds.length) {
		throw new NullPointerException("tabText, selectedIconId and unselectedIconId should has same size");
	}

	LayoutParams params = new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
	params.weight = 1;
	params.gravity = Gravity.CENTER;
	ColorStateList colorState = new ColorStateList(new int[][]{
			new int[]{android.R.attr.state_selected},
			new int[]{}
	}, textColor);

	LinearLayout.LayoutParams iconParams = null;
	if (mIconSize != 0) {
		iconParams = new LinearLayout.LayoutParams(mIconSize, mIconSize);
		iconParams.gravity = Gravity.CENTER;
	}
	for (int i = 0; i < tabText.length; i++) {
		View childView = View.inflate(getContext(), R.layout.bl_item_tab_layout, null);
		TextView textView = childView.findViewById(R.id.bl_tab_text);
		ImageView tabIcon = childView.findViewById(R.id.bl_tab_icon);
		textView.setText(tabText[i]);
		textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
		textView.setTextColor(colorState);
		if (mMiddleGap != 0) {
			textView.setPadding(0, mMiddleGap, 0, 0);
		}
		if (iconParams != null) {
			tabIcon.setLayoutParams(iconParams);
		}
		ViewBgUtil.setTextColor(textView, android.R.attr.state_selected, textColor);
		ViewBgUtil.setSelectorBg(tabIcon, android.R.attr.state_selected, new int[]{
				normalIconIds[i], selectedIconIds[i]});
		addView(childView, params);
	}
}
 
Example 10
Source File: ImageLoaderMainActivity.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_loader_main);

    // Example of a call to a native method
    TextView tv = (TextView) findViewById(R.id.sample_text);
    tv.setText(stringFromJNI());
}
 
Example 11
Source File: WeatherSearchActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
private void init() {
    TextView city = (TextView) findViewById(R.id.city);
    city.setText(cityname);
    forecasttv = (TextView) findViewById(R.id.forecast);
    reporttime1 = (TextView) findViewById(R.id.reporttime1);
    reporttime2 = (TextView) findViewById(R.id.reporttime2);
    weather = (TextView) findViewById(R.id.weather);
    Temperature = (TextView) findViewById(R.id.temp);
    wind = (TextView) findViewById(R.id.wind);
    humidity = (TextView) findViewById(R.id.humidity);
}
 
Example 12
Source File: TrendingReposTimeSpanAdapter.java    From githot with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View view, ViewGroup parent) {
    if (view == null || !view.getTag().toString().equals("DROPDOWN")) {
        view = ((Activity) mContext).getLayoutInflater().inflate(R.layout.trending_repos_timespan_list_item_actionbar, parent, false);
        view.setTag("DROPDOWN");
    }

    TextView textView = (TextView) view.findViewById(android.R.id.text1);
    textView.setText(getItem(position).toString());

    return view;
}
 
Example 13
Source File: KgNumberLayout.java    From BooheeRuler with MIT License 5 votes vote down vote up
private void init(Context context){
    LayoutInflater.from(context).inflate(R.layout.layout_kg_number,this);
    tv_scale = (TextView) findViewById(R.id.tv_scale);
    tv_kg = (TextView) findViewById(R.id.tv_kg);

    tv_scale.setTextSize(TypedValue.COMPLEX_UNIT_PX,mScaleTextSize);
    tv_scale.setTextColor(mScaleTextColor);

    tv_kg.setTextSize(TypedValue.COMPLEX_UNIT_PX,mKgTextSize);
    tv_kg.setTextColor(mKgTextColor);
    tv_kg.setText(mUnitText);
}
 
Example 14
Source File: DeviceDetailActivity.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 追加信息头
 *
 * @param adapter
 * @param title
 */
private void appendHeader(final MergeAdapter adapter, final String title) {
    final LinearLayout lt = (LinearLayout) getLayoutInflater().inflate(R.layout.list_item_view_header, null);
    final TextView tvTitle = (TextView) lt.findViewById(R.id.title);
    tvTitle.setText(title);

    adapter.addView(lt);
}
 
Example 15
Source File: OutSideFrameTabLayout.java    From Collection-Android with MIT License 5 votes vote down vote up
private void updateTabStates() {

        for (int i = 0; i < mTabCount; i++) {
            View v = mTabsContainer.getChildAt(i);
            TextView tv_tab_title = v.findViewById(R.id.tv_tab_title);
            if (tv_tab_title != null) {
                tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnSelectColor);
                tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
                tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
                if (mTextAllCaps) {
                    tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
                }
            }
        }
    }
 
Example 16
Source File: CustomExpandableListAdapter.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
@Override
public View getChildView(int listPosition, final int expandedListPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {
    final String expandedListText = (String) getChild(listPosition, expandedListPosition);
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(R.layout.sensors_list_item, null);
    }
    TextView expandedListTextView = (TextView) convertView
            .findViewById(R.id.expandedListItem);
    expandedListTextView.setText(expandedListText);
    return convertView;
}
 
Example 17
Source File: VerifyActivity.java    From sealrtc-android with MIT License 5 votes vote down vote up
private void initView() {
    btn_login = (Button) findViewById(R.id.btn_login);
    reg_getcode = (Button) findViewById(R.id.reg_getcode);
    btn_login.setOnClickListener(onClickListener);
    btn_login.setClickable(false);

    reg_getcode.setOnClickListener(onClickListener);
    edit_phone = (EditText) findViewById(R.id.edit_phone);
    String phone = SessionManager.getInstance().getString(UserUtils.PHONE);
    if (!TextUtils.isEmpty(phone)) {
        edit_phone.setText(phone);
        reg_getcode.setClickable(true);
        reg_getcode.setBackgroundDrawable(
            getResources().getDrawable(R.drawable.rs_select_btn_blue));
    }
    tv_tips = (TextView) findViewById(R.id.tv_tips);
    edit_verificationCode = (EditText) findViewById(R.id.edit_verificationCode);
    versionCodeView = (TextView) findViewById(R.id.main_page_version_code);
    versionCodeView.setText(
        getResources().getString(R.string.blink_description_version)
            + BuildConfig.VERSION_NAME
            + (BuildConfig.DEBUG ? "_Debug" : ""));
    versionCodeView.setTextColor(getResources().getColor(R.color.blink_text_green));
    mTvRegion = (TextView) findViewById(R.id.tv_region);
    mTvCountry = (TextView) findViewById(R.id.tv_country);
    mTvCountry.setOnClickListener(onClickListener);
    updateCountry();
    img_logo = (ImageView) findViewById(R.id.img_logo);
    if (img_logo != null) {
        if (ServerUtils.usePrivateCloud()) {
            img_logo.setImageResource(R.drawable.ic_launcher_privatecloud);
        } else {
            img_logo.setImageResource(R.drawable.ic_launcher);
        }
    }
}
 
Example 18
Source File: SatelliteMenuView.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
public void setImgText(ImgTextEntity entity) {
    final Context context = getContext();
    TextView textView = new TextView(context);
    @SuppressLint("RestrictedApi")
    Typeface typeface = TypefaceCompat.createFromResourcesFontFile(context, getResources(), R.font.crazydailyicon, "", 0);
    textView.setTypeface(typeface);
    textView.setText(entity.text);
    textView.setTextSize(SIZE * BUTTON_RATIO * TEXT_RATIO);
    OvalShape shape = new OvalShape();
    PaintDrawable shapeDrawable = new PaintDrawable(entity.color);
    shapeDrawable.setShape(shape);
    textView.setTextColor(Color.WHITE);
    textView.setBackground(shapeDrawable);
    textView.setGravity(Gravity.CENTER);
    final int size = (int) (SIZE * BUTTON_RATIO);
    LayoutParams params = new LayoutParams(size, size);
    params.gravity = Gravity.END | Gravity.BOTTOM;
    addView(textView, params);
    mButtonView = textView;
    mButtonView.setOnClickListener(v -> {
        if (isOpen) {
            close();
        } else {
            show();
        }
    });
}
 
Example 19
Source File: Talk.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_talk);

    Toolbar toolbar = (Toolbar) findViewById(R.id.talk_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final TalkDetails talkDetails = (TalkDetails)getIntent().getSerializableExtra("TalkDetails");
    final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    upArrow.setColorFilter(ContextCompat.getColor(this, android.R.color.white), PorterDuff.Mode.SRC_ATOP);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(upArrow);

    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.talk_toolbar_layout);
    collapsingToolbarLayout.setTitle(talkDetails.getName());
    collapsingToolbarLayout.setExpandedTitleColor(ContextCompat.getColor(this, android.R.color.white));
    collapsingToolbarLayout.setCollapsedTitleTextColor(ContextCompat.getColor(this, android.R.color.white));

    final ImageView talkImage = (ImageView) findViewById(R.id.talk_collapsible_image);
    TextView talkTime = (TextView) findViewById(R.id.talk_time_detail);
    TextView talkLocation = (TextView) findViewById(R.id.talk_venue_detail);
    TextView talkDesc = (TextView) findViewById(R.id.talk_desc_detail);

    SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a");
    String talkTimeText = dateFormat.format(talkDetails.getStartTime())
            + " - " + dateFormat.format(talkDetails.getEndTime());
    talkTime.setText(talkTimeText);

    talkLocation.setText(talkDetails.getLocation());
    talkDesc.setText(talkDetails.getDesc());

    Picasso.with(this)
            .load(Uri.parse(talkDetails.getImageURL()))
            .error(R.drawable.placeholder_1)
            .fit().centerCrop().into(talkImage, new com.squareup.picasso.Callback() {
        @Override
        public void onSuccess() {
            applyPalette(talkImage);
        }

        @Override
        public void onError() {
            Log.d("Talk.java", "Error caused by Picasso");
            applyPalette(talkImage);
        }
    });

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.talk_reminder);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.setType("vnd.android.cursor.item/event");
            intent.putExtra(CalendarContract.Events.TITLE,
                    talkDetails.getName());
            intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                    talkDetails.getStartTime().getTime());
            intent.putExtra(CalendarContract.Events.EVENT_LOCATION,
                    talkDetails.getLocation());
            intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                    talkDetails.getEndTime().getTime());
            intent.putExtra(CalendarContract.Events.ALL_DAY, false);
            intent.putExtra(CalendarContract.Events.DESCRIPTION,
                    talkDetails.getShortDesc());
            v.getContext().startActivity(intent);
        }
    });
}
 
Example 20
Source File: AppSetting.java    From MiHomePlus with MIT License 4 votes vote down vote up
private boolean getSetting() {

        int readSettingTimes = 0;

        SharedPreferences settings = getSharedPreferences(data, 0);
        Hosts = settings.getString(addressField, "");

        if (Hosts.equals("")) {
            tellUser("伺服器不能為空");
            return false;
        }

        getSettingbyServer();

        TextView room = (TextView) findViewById(R.id.roomField);
        TextView devices = (TextView) findViewById(R.id.devicesField);
        room.setText("正在重新同步...");
        devices.setText("正在重新同步...");

        tellUser("正在讀取");

        do {
            readSettingTimes = readSettingTimes + 1;
            SystemClock.sleep(1500);
            if (readSettingTimes >= 3) {
                tellUser("讀取配置超時");
                return false;
            }
        } while (!isSettingReadly);

        Log.i(TAG, "getSettingJSON: " + getSettingJSON);

        try {
            JSONObject settingData = new JSONObject(getSettingJSON);
            settingDevices = settingData.getString("devices");
            settingRoom = settingData.getString("room");

            settings.edit()
                    .putString(settingRoomField, settingRoom)
                    .putString(settingDevicesField, settingDevices)
                    .apply();

            Log.i(TAG, "settingDevices: " + settingDevices);
            Log.i(TAG, "settingRoom: " + settingRoom);


            settings = getSharedPreferences(data, 0);

            room.setText(settings.getString(settingRoomField, "房間名稱"));
            devices.setText(settings.getString(settingDevicesField, "設備列表"));

            tellUser("讀取成功");

            return true;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        tellUser("讀取失敗");
        return false;
    }