List of usage examples for android.widget TextView TextView
public TextView(Context context)
From source file:com.example.drugsformarinemammals.Dose_Information.java
public TextView createInformationTextView() { TextView information_textview = new TextView(this); information_textview.setTextColor(Color.BLACK); information_textview.setTextSize(16); information_textview.setTypeface(Typeface.SANS_SERIF); return information_textview; }
From source file:com.commonsware.cwac.crossport.design.widget.TextInputLayout.java
/** * Whether the error functionality is enabled or not in this layout. Enabling this * functionality before setting an error message via {@link #setError(CharSequence)}, will mean * that this layout will not change size when an error is displayed. * * @attr ref android.support.design.R.styleable#TextInputLayout_errorEnabled *//*from www. j a v a2s . c o m*/ public void setErrorEnabled(boolean enabled) { if (mErrorEnabled != enabled) { if (mErrorView != null) { mErrorView.animate().cancel(); } if (enabled) { mErrorView = new TextView(getContext()); mErrorView.setId(R.id.textinput_error); if (mTypeface != null) { mErrorView.setTypeface(mTypeface); } boolean useDefaultColor = false; try { TextViewCompat.setTextAppearance(mErrorView, mErrorTextAppearance); if (Build.VERSION.SDK_INT >= 23 && mErrorView.getTextColors().getDefaultColor() == Color.MAGENTA) { // Caused by our theme not extending from Theme.Design*. On API 23 and // above, unresolved theme attrs result in MAGENTA rather than an exception. // Flag so that we use a decent default useDefaultColor = true; } } catch (Exception e) { // Caused by our theme not extending from Theme.Design*. Flag so that we use // a decent default useDefaultColor = true; } if (useDefaultColor) { // Probably caused by our theme not extending from Theme.Design*. Instead // we manually set something appropriate TextViewCompat.setTextAppearance(mErrorView, android.R.style.TextAppearance_Material_Caption); mErrorView.setTextColor( ContextCompat.getColor(getContext(), R.color.design_textinput_error_color_light)); } mErrorView.setVisibility(INVISIBLE); ViewCompat.setAccessibilityLiveRegion(mErrorView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); addIndicator(mErrorView, 0); } else { mErrorShown = false; updateEditTextBackground(); removeIndicator(mErrorView); mErrorView = null; } mErrorEnabled = enabled; } }
From source file:de.da_sense.moses.client.FormFragment.java
/** * Displays a text question to the user. * @param question the question to be displayed * @param linearLayoutInsideAScrollView the view to add the question to * @param ordinal the ordinal number of the question i.e. 1, 2, 3, 4 or 5 *//*from w w w .j a va 2 s.com*/ private void makeTextQuestion(final Question question, LinearLayout linearLayoutInsideAScrollView, int ordinal) { LinearLayout questionContainer = generateQuestionContainer(linearLayoutInsideAScrollView); TextView questionView = new TextView(getActivity()); questionView.setText(ordinal + ". " + question.getTitle()); if (question.isMandatory()) questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyleMandatory); else questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyle); questionContainer.addView(questionView); mQuestionTitleMappings.put(question, questionView); final EditText editText = new EditText(getActivity()); String madeAnswer = question.getAnswer(); if (!madeAnswer.equals(Question.ANSWER_UNANSWERED)) editText.setText(madeAnswer); if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY) editText.setEnabled(false); else { // remember the answer as soon as the edittext looses focus editText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { String newAnswer = editText.getText().toString(); if (!newAnswer.equals(Question.ANSWER_UNANSWERED)) question.setAnswer(newAnswer); } } }); } editText.setVisibility(View.VISIBLE); if (question.getAnswer() != null) { editText.setText(question.getAnswer()); } mQuestionEditTextMappings.put(question, editText); questionContainer.addView(editText); }
From source file:busradar.madison.StopDialog.java
@Override public void show() { new Thread() { @Override/*from ww w .ja v a 2 s . co m*/ public void run() { for (final RouteURL r : routes) { G.activity.runOnUiThread(new Runnable() { public void run() { cur_loading_text .setText(String.format("Loading route %s...", G.route_points[r.route].name)); } }); final ArrayList<RouteTime> curtimes = new ArrayList<RouteTime>(); try { System.err.printf("BusRadar URL %s\n", TRANSITTRACKER_URL + r.url); URL url = new URL(TRANSITTRACKER_URL + r.url); URLConnection url_conn = url.openConnection(); if (url_conn instanceof HttpsURLConnection) { ((HttpsURLConnection) url_conn).setHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }); } InputStream is = url_conn.getInputStream(); Scanner scan = new Scanner(is, "UTF-8"); //String outstr_cur = "Route " + r.route + "\n"; if (scan.findWithinHorizon(num_vehicles_re, 0) != null) { while (scan.findWithinHorizon(time_re, 0) != null) { RouteTime time = new RouteTime(); time.route = r.route; time.time = scan.match().group(1).replace(".", ""); time.dir = scan.match().group(2); //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time); SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US); time.date = f.parse(time.time); r.status = RouteURL.DONE; //outstr_cur += String.format("%s to %s\n", time.time, time.dir); curtimes.add(time); } while (scan.findWithinHorizon(time_re_backup, 0) != null) { RouteTime time = new RouteTime(); time.route = r.route; time.time = scan.match().group(1).replace(".", ""); //time.dir = scan.match().group(2); //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time); SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US); time.date = f.parse(time.time); r.status = RouteURL.DONE; //outstr_cur += String.format("%s to %s\n", time.time, time.dir); curtimes.add(time); } } // else if (scan.findWithinHorizon(no_busses_re, 0) != null) { // r.status = RouteURL.NO_MORE_TODAY; // } // else if (scan.findWithinHorizon(no_timepoints_re, 0) != null) { // r.status = RouteURL.NO_TIMEPOINTS; // } // else { // r.status = RouteURL.ERROR; // System.out.printf("BusRadar: Could not get stop info for %s\n", r.url); // // throw new Exception("Error parsing TransitTracker webpage."); // } else { r.status = RouteURL.NO_STOPS_UNKONWN; } //r.text = outstr_cur; G.activity.runOnUiThread(new Runnable() { public void run() { times.addAll(curtimes); StopDialog.this.update_times(); } }); } // catch (final IOException ioe) { // log_problem(ioe); // G.activity.runOnUiThread(new Runnable() { // public void run() { // final Context ctx = StopDialog.this.getContext(); // // StopDialog.this.setContentView(new RelativeLayout(ctx) {{ // addView(new TextView(ctx) {{ // setText(Html.fromHtml("Error downloading data. Is the data connection enabled?"+ // "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>"+ioe)); // setPadding(5, 5, 5, 5); // this.setMovementMethod(LinkMovementMethod.getInstance()); // }}, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); // }}); // } // }); // return; // } catch (Exception e) { log_problem(e); String custom_msg = ""; final String turl = TRANSITTRACKER_URL + r.url; if ((e instanceof SocketException) || (e instanceof UnknownHostException)) { // data connection doesn't work custom_msg = "Error downloading data. Is the data connection enabled?" + "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>" + TextUtils.htmlEncode(e.toString()); } else { String rurl = String.format( "http://www.cityofmadison.com/metro/BusStopDepartures/StopID/%04d.pdf", stopid); custom_msg = "Trouble retrieving real-time arrival estimates from <a href='" + turl + "'>this</a> TransitTracker webpage, which is displayed below. " + "Meanwhile, try PDF timetable <a href='" + rurl + "'>here</a>. " + "Contact us at <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a> to report the problem.<p>" + TextUtils.htmlEncode(e.toString()); } final String msg = custom_msg; G.activity.runOnUiThread(new Runnable() { public void run() { final Context ctx = StopDialog.this.getContext(); StopDialog.this.setContentView(new RelativeLayout(ctx) { { addView(new TextView(ctx) { { setId(1); setText(Html.fromHtml(msg)); setPadding(5, 5, 5, 5); this.setMovementMethod(LinkMovementMethod.getInstance()); } }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); addView(new WebView(ctx) { { setWebViewClient(new WebViewClient()); loadUrl(turl); } }, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT) { { addRule(RelativeLayout.BELOW, 1); } }); } }); } }); return; } } G.activity.runOnUiThread(new Runnable() { public void run() { cur_loading_text.setText(""); } }); } }.start(); super.show(); }
From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java
@Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView txt = (TextView) convertView; if (txt == null) { txt = new TextView(getApplication()); txt.setPadding(UI._DLGdppad, UI._DLGsppad, UI._DLGdppad, UI._DLGsppad); txt.setTypeface(UI.defaultTypeface); txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp); txt.setTextColor(defaultTextColors); }//from www . j a v a2s . co m txt.setText(getGenreString(position)); return txt; }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); final SharedPreferences settings = activity.getApiCall().settings; sort = settings.getString("CommentSort", "Best"); boolean newData = true; if (commentData != null) { newData = false;// ww w. j av a2 s . c om } mainView = inflater.inflate(R.layout.single_image_layout, container, false); String[] mMenuList = getResources().getStringArray(R.array.emptyList); if (commentAdapter == null) commentAdapter = new CommentAdapter(mainView.getContext()); commentLayout = (ListView) mainView.findViewById(R.id.comment_thread); commentLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE); if (settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT)) imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.image_view, null); else imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.dark_image_view, null); mPullToRefreshLayout = (PullToRefreshLayout) mainView.findViewById(R.id.ptr_layout); ActionBarPullToRefresh.from(getActivity()) // Mark All Children as pullable .allChildrenArePullable() // Set the OnRefreshListener .listener(this) // Finally commit the setup to our PullToRefreshLayout .setup(mPullToRefreshLayout); if (savedInstanceState != null && newData) { imageData = savedInstanceState.getParcelable("imageData"); inGallery = savedInstanceState.getBoolean("inGallery"); } LinearLayout layout = (LinearLayout) imageLayoutView.findViewById(R.id.image_buttons); TextView imageDetails = (TextView) imageLayoutView.findViewById(R.id.single_image_details); layout.setVisibility(View.VISIBLE); ImageButton imageFullscreen = (ImageButton) imageLayoutView.findViewById(R.id.fullscreen); imageUpvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_good); imageDownvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_bad); ImageButton imageFavorite = (ImageButton) imageLayoutView.findViewById(R.id.rating_favorite); imageComment = (ImageButton) imageLayoutView.findViewById(R.id.comment); ImageButton imageUser = (ImageButton) imageLayoutView.findViewById(R.id.user); imageScore = (TextView) imageLayoutView.findViewById(R.id.single_image_score); TextView imageInfo = (TextView) imageLayoutView.findViewById(R.id.single_image_info); Log.d("imageData", imageData.getJSONObject().toString()); if (imageData.getJSONObject().has("ups")) { imageUpvote.setVisibility(View.VISIBLE); imageDownvote.setVisibility(View.VISIBLE); imageScore.setVisibility(View.VISIBLE); imageComment.setVisibility(View.VISIBLE); ImageUtils.updateImageFont(imageData, imageScore); } imageInfo.setVisibility(View.VISIBLE); ImageUtils.updateInfoFont(imageData, imageInfo); imageUser.setVisibility(View.VISIBLE); imageFavorite.setVisibility(View.VISIBLE); try { if (!imageData.getJSONObject().has("account_url") || imageData.getJSONObject().getString("account_url").equals("null") || imageData.getJSONObject().getString("account_url").equals("[deleted]")) imageUser.setVisibility(View.GONE); if (!imageData.getJSONObject().has("vote")) { imageUpvote.setVisibility(View.GONE); imageDownvote.setVisibility(View.GONE); } else { if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("up")) imageUpvote.setImageResource(R.drawable.green_rating_good); else if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("down")) imageDownvote.setImageResource(R.drawable.red_rating_bad); } if (imageData.getJSONObject().getString("favorite") != null && imageData.getJSONObject().getBoolean("favorite")) imageFavorite.setImageResource(R.drawable.green_rating_favorite); } catch (JSONException e) { Log.e("Error!", e.toString()); } imageFavorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.favoriteImage(singleImageFragment, imageData, (ImageButton) view, activity.getApiCall()); } }); imageUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.gotoUser(singleImageFragment, imageData); } }); imageComment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Activity activity = getActivity(); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_body); newBody.setLines(3); final TextView characterCount = new TextView(activity); characterCount.setText("140"); LinearLayout commentReplyLayout = new LinearLayout(activity); newBody.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { // } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { characterCount.setText(String.valueOf(140 - charSequence.length())); } @Override public void afterTextChanged(Editable editable) { for (int i = editable.length(); i > 0; i--) { if (editable.subSequence(i - 1, i).toString().equals("\n")) editable.replace(i - 1, i, ""); } } }); commentReplyLayout.setOrientation(LinearLayout.VERTICAL); commentReplyLayout.addView(newBody); commentReplyLayout.addView(characterCount); new AlertDialog.Builder(activity).setTitle(R.string.dialog_comment_on_image_title) .setView(commentReplyLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newBody.getText() != null && newBody.getText().toString().length() < 141) { HashMap<String, Object> commentMap = new HashMap<String, Object>(); try { commentMap.put("comment", newBody.getText().toString()); commentMap.put("image_id", imageData.getJSONObject().getString("id")); Fetcher fetcher = new Fetcher(singleImageFragment, "3/comment/", ApiCall.POST, commentMap, ((ImgurHoloActivity) getActivity()).getApiCall(), POSTCOMMENT); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } }); imageUpvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.upVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); imageDownvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.downVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); if (popupWindow != null) { popupWindow.dismiss(); } popupWindow = new PopupWindow(); imageFullscreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.fullscreen(singleImageFragment, imageData, popupWindow, mainView); } }); ArrayAdapter<String> tempAdapter = new ArrayAdapter<String>(mainView.getContext(), R.layout.drawer_list_item, mMenuList); Log.d("URI", "YO I'M IN YOUR SINGLE FRAGMENT gallery:" + inGallery); imageView = (ImageView) imageLayoutView.findViewById(R.id.single_image_view); loadImage(); TextView imageTitle = (TextView) imageLayoutView.findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView.findViewById(R.id.single_image_description); try { String size = String .valueOf(NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_WIDTH))) + "x" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_HEIGHT)) + " (" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_SIZE)) + "B)"; String initial = imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) + " " + Html.fromHtml("•") + " " + size + " " + Html.fromHtml("•") + " " + "Views: " + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_VIEWS)); imageDetails.setText(initial); Log.d("imagedata", imageData.getJSONObject().toString()); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) imageTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); else imageTitle.setVisibility(View.GONE); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) { imageDescription .setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); commentLayout.addHeaderView(imageLayoutView); commentLayout.setAdapter(tempAdapter); } catch (JSONException e) { Log.e("Text Error!", e.toString()); } if ((savedInstanceState == null || commentData == null) && newData) { commentData = new JSONParcelable(); getComments(); commentLayout.setAdapter(commentAdapter); } else if (newData) { commentArray = savedInstanceState.getParcelableArrayList("commentData"); commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } else if (commentArray != null) { commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } return mainView; }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java
private void AddLogMessage(final String Message) { try {//from w w w. ja v a 2 s . co m addMessageProgressDialog = new ProgressDialog(getActivity()); addMessageProgressDialog.setTitle("Contacting Zenoss"); addMessageProgressDialog.setMessage("Please wait:\nProcessing Event Log Updates"); addMessageProgressDialog.show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "AddLogMessage Dialog", e); } addLogMessageHandler = new Handler() { public void handleMessage(Message msg) { addMessageProgressDialog.dismiss(); if (msg.what == 1) { try { String[] tmp = LogEntries.clone(); final int NewArrlength = tmp.length + 1; LogEntries = new String[NewArrlength]; LogEntries[0] = "<strong>" + settings.getString("userName", "") + "</strong> wrote " + Message + "\n<br/><strong>At:</strong> Just now"; for (int i = 1; i < NewArrlength; ++i) // { LogEntries[i] = tmp[(i - 1)]; } TextView newLog = new TextView(getActivity()); newLog.setText(Html.fromHtml(LogEntries[0])); newLog.setPadding(0, 6, 0, 6); logList.addView(newLog); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddMessageProgressHandler", e); try { Toast.makeText(getActivity(), "The log message was successfully sent to Zenoss but an error occured when updating the UI", Toast.LENGTH_LONG).show(); } catch (Exception e1) { BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddMessageProgressHandler Toast", e1); } } } else { try { Toast.makeText(getActivity(), "An error was encountered adding your message to the log", Toast.LENGTH_LONG).show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddMessageProgressHandler", e); } } } }; addLogMessageThread = new Thread() { public void run() { Boolean Success = false; try { if (API == null) { if (settings.getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) { API = new ZenossAPIZaas(); } else { API = new ZenossAPICore(); } ZenossCredentials credentials = new ZenossCredentials(getActivity()); API.Login(credentials); } Success = API.AddEventLog(getArguments().getString("EventID"), Message); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddLogMessageThread", e); addLogMessageHandler.sendEmptyMessage(0); } if (Success) { addLogMessageHandler.sendEmptyMessage(1); } else { addLogMessageHandler.sendEmptyMessage(0); } } }; addLogMessageThread.start(); }
From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java
@SuppressWarnings("deprecation") public void displaydata(final AccountData result, boolean fromcache) { if (getActivity() == null) { return;//from w ww.j av a 2s . c o m } svAccount.setVisibility(View.VISIBLE); llLoading.setVisibility(View.GONE); unsupportedErrorView.setVisibility(View.GONE); answerErrorView.setVisibility(View.GONE); errorView.removeAllViews(); this.fromcache = fromcache; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(app.getApplicationContext()); final int tolerance = Integer.parseInt(sp.getString("notification_warning", "3")); tvAccLabel.setText(account.getLabel()); tvAccUser.setText(account.getName()); Library lib; try { lib = app.getLibrary(account.getLibrary()); tvAccCity.setText(lib.getDisplayName()); } catch (IOException e) { ErrorReporter.handleException(e); e.printStackTrace(); } catch (JSONException e) { ErrorReporter.handleException(e); } /* Lent items */ llLent.removeAllViews(); final boolean notification_on = sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false); boolean notification_problems = false; if (tvWarning != null) { if (result.getWarning() != null && result.getWarning().length() > 1) { tvWarning.setVisibility(View.VISIBLE); tvWarning.setText(result.getWarning()); } else { tvWarning.setVisibility(View.GONE); } } if (result.getLent().size() == 0) { TextView t1 = new TextView(getActivity()); t1.setText(R.string.entl_none); llLent.addView(t1); tvLentHeader.setText(getActivity().getString(R.string.lent_head) + " (0)"); } else { tvLentHeader .setText(getActivity().getString(R.string.lent_head) + " (" + result.getLent().size() + ")"); lentManager = new ExpandingCardListManager(getActivity(), llLent) { @Override public View getView(final int position, ViewGroup container) { final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_lent, container, false); LentViewHolder holder = new LentViewHolder(); holder.findViews(v); final LentItem item = result.getLent().get(position); // Expanding and closing details v.setClickable(true); v.setFocusable(true); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getExpandedPosition() != position) { expand(position); } else { collapse(); } } }); if (item.getId() != null) { // Connection to detail view holder.ivDetails.setOnClickListener(new OnClickListener() { @Override public void onClick(View clicked) { Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class); intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId()); ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v, v.getLeft(), v.getTop(), v.getWidth(), v.getHeight()); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); } }); holder.hasDetailLink = true; } // Overview (Title/Author, Status/Deadline) if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getTitle()); } else { setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor); } DateTimeFormatter fmt = DateTimeFormat.shortDate(); if (item.getDeadline() != null && item.getStatus() != null) { holder.tvStatus.setText( fmt.print(item.getDeadline()) + " (" + Html.fromHtml(item.getStatus()) + ")"); } else if (item.getDeadline() != null) { holder.tvStatus.setText(fmt.print(new LocalDate(item.getDeadline()))); } else { setHtmlTextOrHide(item.getStatus(), holder.tvStatus); } // Detail setTextOrHide(item.getAuthor(), holder.tvAuthorDetail); setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail); if (item.getLendingBranch() != null && item.getHomeBranch() != null) { holder.tvBranchDetail .setText(Html.fromHtml(item.getLendingBranch() + " / " + item.getHomeBranch())); } else if (item.getLendingBranch() != null) { holder.tvBranchDetail.setText(Html.fromHtml(item.getLendingBranch())); } else { setHtmlTextOrHide(item.getHomeBranch(), holder.tvBranchDetail); } // Color codes for return dates if (item.getDeadline() != null) { if (item.getDeadline().equals(LocalDate.now()) || item.getDeadline().isBefore(LocalDate.now())) { holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_overdue)); } else if (Days.daysBetween(LocalDate.now(), item.getDeadline()).getDays() <= tolerance) { holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_warning)); } else if (item.getDownloadData() != null) { holder.vStatusColor .setBackgroundColor(getResources().getColor(R.color.account_downloadable)); } } else if (item.getDownloadData() != null) { holder.vStatusColor .setBackgroundColor(getResources().getColor(R.color.account_downloadable)); } if (item.getProlongData() != null) { holder.ivProlong.setTag(item.getProlongData()); holder.ivProlong.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { prolong((String) arg0.getTag()); } }); holder.ivProlong.setVisibility(View.VISIBLE); holder.ivProlong.setAlpha(item.isRenewable() ? 255 : 100); } else if (item.getDownloadData() != null && app.getApi() instanceof EbookServiceApi) { holder.ivDownload.setTag(item.getDownloadData()); holder.ivDownload.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { download((String) arg0.getTag()); } }); holder.ivProlong.setVisibility(View.GONE); holder.ivDownload.setVisibility(View.VISIBLE); } else { holder.ivProlong.setVisibility(View.INVISIBLE); } v.setTag(holder); return v; } @Override public void expandView(int position, View view) { LentViewHolder holder = (LentViewHolder) view.getTag(); LentItem item = result.getLent().get(position); holder.llDetails.setVisibility(View.VISIBLE); setHtmlTextOrHide(item.getTitle(), holder.tvTitleAndAuthor); if (holder.hasDetailLink) holder.ivDetails.setVisibility(View.VISIBLE); } @Override public void collapseView(int position, View view) { LentViewHolder holder = (LentViewHolder) view.getTag(); LentItem item = result.getLent().get(position); holder.llDetails.setVisibility(View.GONE); if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getAuthor()); holder.tvTitleAndAuthor.setVisibility(View.VISIBLE); } holder.ivDetails.setVisibility(View.GONE); } @Override public int getCount() { return result.getLent().size(); } }; lentManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() { private float llDataY; private float llDataTranslationY = 0; @Override public void beforeExpand(View unexpandedView) { LentViewHolder holder = (LentViewHolder) unexpandedView.getTag(); llDataY = ViewHelper.getY(holder.llData); } @Override public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) { LentViewHolder holder = (LentViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(-heightDifference, 0); // Animate buttons to the side int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0)); // Animate llData to the bottom if required if (ViewHelper.getY(holder.llData) != llDataY) { ViewHelper.setY(holder.llData, llDataY); llDataTranslationY = ViewHelper.getTranslationY(holder.llData); anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0)); } else { llDataTranslationY = 0; } return anims; } @Override public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) { LentViewHolder holder = (LentViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(0, heightDifference); // Animate buttons back int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference)); // Animate llData back anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY)); return anims; } @Override public void onCollapseAnimationEnd() { if (view.findViewById(R.id.rlMeta) != null) { // tablet ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0); } else { // phone ViewHelper.setTranslationY(tvResHeader, 0); ViewHelper.setTranslationY(llRes, 0); ViewHelper.setTranslationY(tvAge, 0); ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0); } } private Collection<Animator> getAnimations(float from, float to) { List<Animator> animators = new ArrayList<>(); if (view.findViewById(R.id.rlMeta) != null) { // tablet if (result.getLent().size() >= result.getReservations().size()) { animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY", from, to)); } } else { // phone animators.add(ObjectAnimator.ofFloat(tvResHeader, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(llRes, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY", from, to)); } return animators; } }); for (final LentItem item : result.getLent()) { try { if (notification_on && item.getDeadline() == null && !item.isEbook()) { notification_problems = true; } } catch (Exception e) { notification_problems = true; } } } if (notification_problems) { if (tvError != null) { tvError.setVisibility(View.VISIBLE); tvError.setText(R.string.notification_problems); } } /* Reservations */ llRes.removeAllViews(); if (result.getReservations().size() == 0) { TextView t1 = new TextView(getActivity()); t1.setText(R.string.reservations_none); llRes.addView(t1); tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (0)"); } else { tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (" + result.getReservations().size() + ")"); resManager = new ExpandingCardListManager(getActivity(), llRes) { @Override public View getView(final int position, ViewGroup container) { final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_reservation, llRes, false); ReservationViewHolder holder = new ReservationViewHolder(); holder.findViews(v); final ReservedItem item = result.getReservations().get(position); // Expanding and closing details v.setClickable(true); v.setFocusable(true); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getExpandedPosition() != position) { expand(position); } else { collapse(); } } }); if (item.getId() != null) { // Connection to detail view holder.ivDetails.setOnClickListener(new OnClickListener() { @Override public void onClick(View clicked) { Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class); intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId()); ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v, v.getLeft(), v.getTop(), v.getWidth(), v.getHeight()); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); } }); holder.hasDetailLink = true; } // Overview (Title/Author, Ready/Expire) if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getTitle()); } else { setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor); } DateTimeFormatter fmt = DateTimeFormat.shortDate(); StringBuilder status = new StringBuilder(); if (item.getStatus() != null) status.append(item.getStatus()); boolean needsBraces = item.getStatus() != null && (item.getReadyDate() != null || item.getExpirationDate() != null); if (needsBraces) status.append(" ("); if (item.getReadyDate() != null) { status.append(getString(R.string.reservation_expire_until)).append(" ") .append(fmt.print(item.getReadyDate())); } if (item.getExpirationDate() != null) { if (item.getReadyDate() != null) status.append(", "); status.append(fmt.print(item.getExpirationDate())); } if (needsBraces) status.append(")"); if (status.length() > 0) { holder.tvStatus.setText(Html.fromHtml(status.toString())); } else { holder.tvStatus.setVisibility(View.GONE); } // Detail setTextOrHide(item.getAuthor(), holder.tvAuthorDetail); setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail); setHtmlTextOrHide(item.getBranch(), holder.tvBranchDetail); if (item.getBookingData() != null) { holder.ivBooking.setTag(item.getBookingData()); holder.ivBooking.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { bookingStart((String) arg0.getTag()); } }); holder.ivBooking.setVisibility(View.VISIBLE); holder.ivCancel.setVisibility(View.GONE); } else if (item.getCancelData() != null) { holder.ivCancel.setTag(item.getCancelData()); holder.ivCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { cancel((String) arg0.getTag()); } }); holder.ivCancel.setVisibility(View.VISIBLE); holder.ivBooking.setVisibility(View.GONE); } else { holder.ivCancel.setVisibility(View.INVISIBLE); holder.ivBooking.setVisibility(View.GONE); } v.setTag(holder); return v; } @Override public void expandView(int position, View view) { ReservationViewHolder holder = (ReservationViewHolder) view.getTag(); ReservedItem item = result.getReservations().get(position); holder.llDetails.setVisibility(View.VISIBLE); setTextOrHide(item.getTitle(), holder.tvTitleAndAuthor); if (holder.hasDetailLink) holder.ivDetails.setVisibility(View.VISIBLE); } @Override public void collapseView(int position, View view) { ReservationViewHolder holder = (ReservationViewHolder) view.getTag(); ReservedItem item = result.getReservations().get(position); holder.llDetails.setVisibility(View.GONE); if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getAuthor()); holder.tvTitleAndAuthor.setVisibility(View.VISIBLE); } holder.ivDetails.setVisibility(View.GONE); } @Override public int getCount() { return result.getReservations().size(); } }; resManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() { private float llDataY; private float llDataTranslationY = 0; @Override public void beforeExpand(View unexpandedView) { ReservationViewHolder holder = (ReservationViewHolder) unexpandedView.getTag(); llDataY = ViewHelper.getY(holder.llData); } @Override public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) { ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(-heightDifference, 0); // Animate buttons to the side int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0)); // Animate llData to the bottom if required if (ViewHelper.getY(holder.llData) != llDataY) { ViewHelper.setY(holder.llData, llDataY); llDataTranslationY = ViewHelper.getTranslationY(holder.llData); anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0)); } else { llDataTranslationY = 0; } return anims; } @Override public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) { ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(0, heightDifference); // Animate buttons back int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference)); // Animate llData back anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY)); return anims; } @Override public void onCollapseAnimationEnd() { if (view.findViewById(R.id.rlMeta) != null) { // tablet ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0); } else { // phone ViewHelper.setTranslationY(tvAge, 0); ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0); } } private Collection<Animator> getAnimations(float from, float to) { List<Animator> animators = new ArrayList<>(); if (view.findViewById(R.id.rlMeta) != null) { // tablet if (result.getReservations().size() >= result.getLent().size()) { animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY", from, to)); } } else { // phone animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY", from, to)); } return animators; } }); } if (result.getPendingFees() != null) { tvPendingFeesLabel.setVisibility(View.VISIBLE); tvPendingFees.setVisibility(View.VISIBLE); tvPendingFees.setText(result.getPendingFees()); } else { tvPendingFeesLabel.setVisibility(View.GONE); tvPendingFees.setVisibility(View.GONE); } if (result.getValidUntil() != null) { tvValidUntilLabel.setVisibility(View.VISIBLE); tvValidUntil.setVisibility(View.VISIBLE); tvValidUntil.setText(result.getValidUntil()); } else { tvValidUntilLabel.setVisibility(View.GONE); tvValidUntil.setVisibility(View.GONE); } refreshage(); }
From source file:com.example.drugsformarinemammals.Dose_Information.java
public void show_dose(ArrayList<Dose_Data> dose, TableLayout dose_table, TableRow dose_data, String drug_name, String group_name, String animal_family, String animal_name, String animal_category, ArrayList<String> notes, ArrayList<String> references, ArrayList<Article_Reference> references_index) { String doseAmount;//from w ww . j a v a 2 s . com String dosePosology; String doseRoute; String doseBookReference; String doseArticleReference; for (int k = 0; k < dose.size(); k++) { if (k > 0) { dose_data = new TableRow(this); } doseAmount = dose.get(k).getAmount(); dosePosology = dose.get(k).getPosology(); doseRoute = dose.get(k).getRoute(); doseBookReference = dose.get(k).getBookReference(); doseArticleReference = dose.get(k).getArticleReference(); //Dose amount data TextView textView_animal_dose_amount = new TextView(this); textView_animal_dose_amount.setText(doseAmount); textView_animal_dose_amount.setSingleLine(false); textView_animal_dose_amount.setTextColor(Color.BLACK); textView_animal_dose_amount.setTextSize(15); textView_animal_dose_amount.setTypeface(Typeface.SANS_SERIF); TableRow.LayoutParams paramsDoseAmount = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseAmount.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_amount, paramsDoseAmount); //Dose posology data TextView textView_animal_dose_posology = new TextView(this); textView_animal_dose_posology.setText(dosePosology); textView_animal_dose_posology.setSingleLine(false); textView_animal_dose_posology.setTextColor(Color.BLACK); textView_animal_dose_posology.setTextSize(15); textView_animal_dose_posology.setTypeface(Typeface.SANS_SERIF); TableRow.LayoutParams paramsDosePosology = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDosePosology.gravity = Gravity.CENTER; if ((screenWidth < 600 && !isCollapsed(drug_name, group_name, animal_family, "Posology")) || screenWidth >= 600) dose_data.addView(textView_animal_dose_posology, paramsDosePosology); //Dose route data TextView textView_animal_dose_route = new TextView(this); textView_animal_dose_route.setText(doseRoute); textView_animal_dose_route.setSingleLine(false); textView_animal_dose_route.setTextColor(Color.BLACK); textView_animal_dose_route.setTextSize(15); textView_animal_dose_route.setTypeface(Typeface.SANS_SERIF); if (screenWidth >= 600) { TableRow.LayoutParams paramsDoseRoute = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseRoute.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_route, paramsDoseRoute); } else { TableRow.LayoutParams paramsDoseRoute = new TableRow.LayoutParams(30, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseRoute.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_route, paramsDoseRoute); } //Dose reference data TextView textView_animal_dose_reference = new TextView(this); if (!doseBookReference.equals("")) textView_animal_dose_reference.setText(doseBookReference); else if (!doseArticleReference.equals("")) { if (!references.contains(doseArticleReference)) { references.add(references.size(), doseArticleReference); Article_Reference article_reference = new Article_Reference(reference_index, doseArticleReference); references_index.add(references_index.size(), article_reference); reference_index++; } int article_index = references.indexOf(doseArticleReference); textView_animal_dose_reference.setText("(" + references_index.get(article_index).getIndex() + ")"); } textView_animal_dose_reference.setSingleLine(false); textView_animal_dose_reference.setTextColor(Color.BLACK); textView_animal_dose_reference.setTextSize(15); textView_animal_dose_reference.setTypeface(Typeface.SANS_SERIF); if (screenWidth >= 600) { TableRow.LayoutParams paramsDoseReference = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseReference.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_reference, paramsDoseReference); } else { TableRow.LayoutParams paramsDoseReference = new TableRow.LayoutParams(150, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseReference.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_reference, paramsDoseReference); } //Specific note index ArrayList<String> specific_notes = new ArrayList<String>(); specific_notes = helper.read_specific_notes(drug_name, group_name, animal_name, animal_family, animal_category, doseAmount, dosePosology, doseRoute, doseBookReference, doseArticleReference); String index = ""; for (int m = 0; m < specific_notes.size(); m++) { String note = specific_notes.get(m); if (!notes.contains(note)) { notes.add(notes.size(), note); } index += "(" + (notes.indexOf(note) + 1) + ") "; } TextView textView_specific_note_index = new TextView(this); textView_specific_note_index.setText(index); textView_specific_note_index.setSingleLine(false); textView_specific_note_index.setTextColor(Color.BLACK); textView_specific_note_index.setTextSize(15); textView_specific_note_index.setTypeface(Typeface.SANS_SERIF); if (screenWidth >= 600 && screenWidth < 720) { TableRow.LayoutParams paramsSpecificNoteIndex = new TableRow.LayoutParams(150, TableRow.LayoutParams.WRAP_CONTENT); paramsSpecificNoteIndex.gravity = Gravity.CENTER; dose_data.addView(textView_specific_note_index, paramsSpecificNoteIndex); } else if (screenWidth >= 720) { TableRow.LayoutParams paramsSpecificNoteIndex = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsSpecificNoteIndex.gravity = Gravity.CENTER; dose_data.addView(textView_specific_note_index, paramsSpecificNoteIndex); } else { TableRow.LayoutParams paramsSpecificNoteIndex = new TableRow.LayoutParams(100, TableRow.LayoutParams.WRAP_CONTENT); paramsSpecificNoteIndex.gravity = Gravity.CENTER; if ((screenWidth < 600 && !isCollapsed(drug_name, group_name, animal_family, "Note")) || screenWidth >= 600) dose_data.addView(textView_specific_note_index, paramsSpecificNoteIndex); } dose_table.addView(dose_data); } }
From source file:com.hybris.mobile.app.commerce.fragment.ProductDetailFragmentBase.java
/** * Create table to show data in a table/*from w w w. j av a 2s .com*/ * * @param volumePricingTable : Table which contains from volume pricing for the current product */ protected void createVolumePricingTable(TableLayout volumePricingTable) { if (mProduct.getVolumePrices() != null) { TableRow headerRow = new TableRow(getActivity()); TextView header1 = new TextView(getActivity()); header1.setText(getString(R.string.product_detail_volume_qty)); header1.setTypeface(null, Typeface.BOLD); headerRow.addView(header1); TextView header2 = new TextView(getActivity()); header2.setText(getString(R.string.product_detail_volume_price)); header2.setTypeface(null, Typeface.BOLD); headerRow.addView(header2); if (mProduct.getVolumePrices().size() > 5) { TextView header3 = new TextView(getActivity()); header3.setText(getString(R.string.product_detail_volume_qty)); header3.setTypeface(null, Typeface.BOLD); headerRow.addView(header3); TextView header4 = new TextView(getActivity()); header4.setText(getString(R.string.product_detail_volume_price)); header4.setTypeface(null, Typeface.BOLD); headerRow.addView(header4); } volumePricingTable.addView(headerRow); for (Price volumePrice : mProduct.getVolumePrices()) { TableRow contentRow = new TableRow(getActivity()); if (volumePrice != null) { TextView content1 = new TextView(getActivity()); content1.setText(volumePrice.getMinQuantity() + " - " + volumePrice.getMaxQuantity()); contentRow.addView(content1); TextView content2 = new TextView(getActivity()); content2.setText(volumePrice.getFormattedValue()); contentRow.addView(content2); if (mProduct.getVolumePrices().size() > 5) { TextView content3 = new TextView(getActivity()); content3.setText(volumePrice.getMinQuantity() + " - " + volumePrice.getMaxQuantity()); contentRow.addView(content3); TextView content4 = new TextView(getActivity()); content4.setText(volumePrice.getFormattedValue()); contentRow.addView(content4); } } else { Log.d(TAG, "Price or Stock is null"); } volumePricingTable.addView(contentRow); } } }