List of usage examples for android.widget TextView setId
public void setId(@IdRes int id)
From source file:cn.mailchat.view.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { //layout/* w ww .ja v a 2 s. com*/ RelativeLayout tabLayout = new RelativeLayout(getContext()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); tabLayout.setLayoutParams(layoutParams); RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); textParams.addRule(RelativeLayout.CENTER_IN_PARENT); //tab TextView tab = new TextView(getContext()); tab.setId(100 + position); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tabLayout.addView(tab, textParams); //??? RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId()); viewParams.addRule(RelativeLayout.CENTER_VERTICAL); View view = new View(getContext()); ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); view.setLayoutParams(vParams); tabLayout.addView(view, viewParams); addTab(position, tabLayout); }
From source file:com.yibairun.ui.components.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { //layout//www . ja v a 2 s .c o m RelativeLayout tabLayout = new RelativeLayout(getContext()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); tabLayout.setLayoutParams(layoutParams); RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); textParams.addRule(RelativeLayout.CENTER_IN_PARENT); //tab TextView tab = new TextView(getContext()); tab.setId(100 + position); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tabLayout.addView(tab, textParams); //??? RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId()); viewParams.addRule(RelativeLayout.CENTER_VERTICAL); View view = new View(getContext()); ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); view.setLayoutParams(vParams); tabLayout.addView(view, viewParams); BadgeView badgeView = new BadgeView(getContext(), view); badgeView.setTextSize(10); badgeView.setGravity(Gravity.CENTER); badgeView.setBadgePosition(BadgeView.POSITION_TOP_LEFT); badgeView.setTag(BAGE_TAG); addTab(position, tabLayout); }
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Show the alert/*w ww . ja v a 2s . c o m*/ * * @param context application-specific resources * @param configuration describes all device configuration information * @param text message to be displayed * @param forceClearPreviousAlert true will clear previous alert else keep it */ @SuppressLint("NewApi") private static void showAlertOnScreen(final Activity context, final Configuration configuration, final String text, boolean forceClearPreviousAlert) { final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content)); boolean currentlyDisplayed = false; int viewId = R.id.alert_view_top; final TextView textView; boolean alertAlreadyExists = false; if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) { viewId = R.id.alert_view_bottom; } // Retrieving the view RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId); if (forceClearPreviousAlert) { mainView.removeView(relativeLayout); relativeLayout = null; } // Creating the view if (relativeLayout == null) { // Main layout relativeLayout = new RelativeLayout(context); relativeLayout.setId(viewId); relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight())); relativeLayout.setGravity(Gravity.CENTER); // Textview textView = new TextView(context); textView.setId(R.id.alert_view_text); textView.setGravity(Gravity.CENTER); textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); relativeLayout.addView(textView); setIcon(context, configuration, relativeLayout, textView); if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) { relativeLayout.setY(-configuration.getHeight()); } else { relativeLayout.setY(mainView.getHeight()); } // Adding the view to the global layout mainView.addView(relativeLayout, 0); relativeLayout.bringToFront(); relativeLayout.requestLayout(); relativeLayout.invalidate(); } // View already exists else { alertAlreadyExists = true; textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text); if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) { if (relativeLayout.getY() == 0) { currentlyDisplayed = true; } } else { if (relativeLayout.getY() < mainView.getHeight()) { currentlyDisplayed = true; } } // The view is currently shown to the user if (currentlyDisplayed) { // If the message is not the same, we hide the current message and display the new one if (!StringUtils.equals(text, textView.getText())) { // Anim out the current message ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout); final RelativeLayout relativeLayoutFinal = relativeLayout; if (viewPropertyAnimator != null) { // Anim in the new message after the animation out has finished if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { viewPropertyAnimator.setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }); } else { viewPropertyAnimator.withEndAction(new Runnable() { @Override public void run() { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }); } } else { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } } } } final RelativeLayout relativeLayoutFinal = relativeLayout; // Close the alert by clicking the layout if (configuration.isCloseable()) { relativeLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { animOut(configuration, mainView, relativeLayoutFinal); v.performClick(); return true; } }); } if (!currentlyDisplayed) { // Set the icon in case the alert already exists but it's not currently displayed if (alertAlreadyExists) { setIcon(context, configuration, relativeLayoutFinal, textView); } // We anim in the alert animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }
From source file:com.yktx.check.widget.OldPagerSlidingTabStrip.java
private void addIconAndTextTab(final int position, int resId, String title) { LinearLayout layout = new LinearLayout(getContext()); layout.setGravity(Gravity.CENTER);/*from w w w .jav a2 s .c o m*/ layout.setOrientation(LinearLayout.VERTICAL); ImageView tabImage = new ImageView(getContext()); tabImage.setImageResource(resId); tabImage.setId(R.id.image); TextView tabText = new TextView(getContext()); tabText.setText(title); tabText.setSingleLine(); tabText.setId(R.id.text); tabText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); tabText.setGravity(Gravity.CENTER_HORIZONTAL); tabText.setPadding(0, 3, 0, 0); layout.addView(tabImage); layout.addView(tabText); addTab(position, layout); }
From source file:com.wit.and.dialog.ListDialog.java
/** * <p>//ww w. j av a2 s. co m * Invoked to create dialog empty view for list view. * </p> * <p> * Here is the best place to provide custom empty view. * </p> * * @param inflater Layout inflater. * @param container Layout created in the {@link #onCreateBodyView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)} * @param savedInstanceState Saved dialog state. * @return Created empty view. */ protected View onCreateEmptyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View emptyView; final ListOptions options = getOptions(); if (options.getEmptyViewRes() != DEFAULT_RES) { // Inflate custom empty view. emptyView = inflater.inflate(options.getEmptyViewRes(), null, false); } else { // Create default empty text view. TextView textView = new TextView(inflater.getContext()); textView.setId(android.R.id.empty); textView.setGravity(Gravity.CENTER); textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); textView.setVisibility(View.GONE); emptyView = textView; } return emptyView; }
From source file:com.landenlabs.all_devtool.ConsoleFragment.java
private TextView addTextView(RelativeLayout relLayout, int belowId, int rightId, int widthDp, int heightDp, int padLeft) { float scale = Resources.getSystem().getDisplayMetrics().density; int widthParam = (widthDp != 0) ? dpToPx(widthDp) : RelativeLayout.LayoutParams.WRAP_CONTENT; int heightParam = (heightDp != 0) ? dpToPx(heightDp) : RelativeLayout.LayoutParams.WRAP_CONTENT; RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(widthParam, heightParam); // params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); if (belowId != 0) params.addRule(RelativeLayout.BELOW, belowId); if (rightId != 0) { if (rightId > 0) params.addRule(RelativeLayout.ALIGN_RIGHT, rightId); else//from w w w. jav a 2 s.c om params.addRule(RelativeLayout.RIGHT_OF, -rightId); } // relLayout.setPadding(padLeft, 0, 0, 0); params.setMargins(padLeft, 0, 0, 0); TextView textView = new TextView(relLayout.getContext()); textView.setLines(1); if (widthDp > 0) textView.setMaxWidth(dpToPx(widthDp)); if (Build.VERSION.SDK_INT >= 17) { textView.setId(View.generateViewId()); } else { textView.setId(sNextId++); } relLayout.addView(textView, params); return textView; }
From source file:com.dahl.brendan.wordsearch.view.WordSearchActivity.java
/** * creates a grid of textViews from layout files based on the gridSize * and sets the new textViews to use the controller as their listener * //from w w w.java2s . c om * @param gridSize square size of the new grid to make * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid */ public void setupViewGrid() { control.setLetter(null); int gridSize = control.getGridSize(); TextViewGridController controller = control.getGridManager(); ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable); if (gridTable.getChildCount() != gridSize) { if (gridTable.getChildCount() == 0) { gridTable.setKeepScreenOn(true); gridTable.setOnTouchListener(controller); } controller.clearPointDemension(); gridTable.removeAllViews(); Point point = new Point(); controller.setGridView(new TextView[gridSize][]); TextView[][] gridView = controller.getGridView(); for (point.y = 0; point.y < gridSize; point.y++) { this.getLayoutInflater().inflate(R.layout.grid_row, gridTable, true); ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y); TextView[] rowText = new TextView[gridSize]; for (point.x = 0; point.x < gridSize; point.x++) { this.getLayoutInflater().inflate(R.layout.grid_text_view, row, true); TextView view = (TextView) row.getChildAt(point.x); view.setId(ConversionUtil.convertPointToID(point, control.getGridSize())); view.setOnKeyListener(controller); rowText[point.x] = view; } gridView[point.y] = rowText; } gridTable.requestLayout(); } }
From source file:org.hfoss.posit.android.functionplugin.reminder.SetReminder.java
/** * Called from FindActivity.onActivityResult(). Used to * update the Find's View, specifically the date, lat, long, * and alarm icon fields./*w ww.j ava 2 s . co m*/ * * @param context, the calling Activity * @param find, the current Find * @param view, the FindActivity's content view * @param intent, the Intent that is passed to the menu activity */ public void onActivityResultCallback(Context context, Find find, View view, Intent intent) { Log.i(TAG, "onActivityResultCallbac"); // Intent is NOT null, meaning it includes reminder // date and location information set by the user if (intent != null) { Bundle bundle = intent.getExtras(); // Get date, longitude, and latitude String date = bundle.getString(Find.TIME); Double longitude = bundle.getDouble(Find.LONGITUDE); Double latitude = bundle.getDouble(Find.LATITUDE); TextView tv = (TextView) view.findViewById(R.id.isAdhocTextView); Integer is_adhoc = bundle.getInt(Find.IS_ADHOC); Log.i(TAG, "is_adhoc = " + is_adhoc); if (tv != null) { Log.i(TAG, "Setting isAdhocTextView to " + is_adhoc); tv.setText("" + is_adhoc); } // Display user specified longitude and latitude tv = (TextView) view.findViewById(R.id.longitudeValueTextView); tv.setText(String.valueOf(longitude)); tv = (TextView) view.findViewById(R.id.latitudeValueTextView); tv.setText(String.valueOf(latitude)); // Remove the old row that displays time and replace it // with a new row that include an alarm clock icon to // visually indicate this find has a reminder attached ViewGroup parent = (ViewGroup) view.findViewById(R.id.timeValueTextView).getParent(); parent.removeAllViews(); ImageView alarmIcon = new ImageView(context); alarmIcon.setImageResource(R.drawable.reminder_alarm); TableRow.LayoutParams lp1 = new TableRow.LayoutParams(30, 30); lp1.setMargins(0, 6, 80, 0); parent.addView(alarmIcon, lp1); TextView mCloneTimeTV = new TextView(context); mCloneTimeTV.setId(R.id.timeValueTextView); mCloneTimeTV.setText(date); mCloneTimeTV.setTextSize(12); TextView mTimeTV = (TextView) view.findViewById(R.id.timeValueTextView); mTimeTV = mCloneTimeTV; TableRow.LayoutParams lp2 = new TableRow.LayoutParams(); lp2.setMargins(6, 6, 0, 0); parent.addView(mTimeTV, lp2); } }
From source file:ws.crandell.newspaperpuzzles.wordsearch.view.WordSearchActivity.java
/** * creates a grid of textViews from layout files based on the gridSize * and sets the new textViews to use the controller as their listener * //from w w w . j ava 2 s.co m * @param gridSize square size of the new grid to make * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid */ public void setupViewGrid() { control.setLetter(null); int gridSize = control.getGridSize(); TextViewGridController controller = control.getGridManager(); ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable); if (gridTable.getChildCount() != gridSize) { if (gridTable.getChildCount() == 0) { gridTable.setKeepScreenOn(true); gridTable.setOnTouchListener(controller); } controller.clearPointDemension(); gridTable.removeAllViews(); Point point = new Point(); controller.setGridView(new TextView[gridSize][]); TextView[][] gridView = controller.getGridView(); for (point.y = 0; point.y < gridSize; point.y++) { this.getLayoutInflater().inflate(R.layout.ws_grid_row, gridTable, true); ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y); TextView[] rowText = new TextView[gridSize]; for (point.x = 0; point.x < gridSize; point.x++) { this.getLayoutInflater().inflate(R.layout.ws_grid_text_view, row, true); TextView view = (TextView) row.getChildAt(point.x); view.setId(ConversionUtil.convertPointToID(point, control.getGridSize())); view.setOnKeyListener(controller); rowText[point.x] = view; } gridView[point.y] = rowText; } gridTable.requestLayout(); } }
From source file:eu.trentorise.smartcampus.communicator.fragments.messages.AbstractMessageListFragment.java
private void updateListFooter(boolean empty) { TextView view = (TextView) getView().findViewById(android.R.id.empty); if (empty) {/*from w w w .j a v a 2 s.c om*/ if (view == null) { view = new TextView(getSherlockActivity()); view.setPadding(5, 5, 5, 5); view.setText(R.string.empty_messages); view.setId(android.R.id.empty); ((ViewGroup) getView()).addView(view); } else { view.setVisibility(View.VISIBLE); } } else if (view != null) { view.setVisibility(View.GONE); } }