List of usage examples for android.widget TextView setOnClickListener
public void setOnClickListener(@Nullable OnClickListener l)
From source file:com.darly.dlclent.widget.springindicator.SpringIndicator.java
private void addTabItems() { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f); tabs = new ArrayList<TextView>(); for (int i = 0; i < viewPager.getAdapter().getCount(); i++) { TextView textView = new TextView(getContext()); if (viewPager.getAdapter().getPageTitle(i) != null) { textView.setText(viewPager.getAdapter().getPageTitle(i)); } else {//from w w w . ja v a 2s . co m textView.setText(i + 1 + ""); } textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); textView.setTextColor(getResources().getColor(textColorId)); if (textBgResId != 0) { textView.setBackgroundResource(textBgResId); } textView.setLayoutParams(layoutParams); final int position = i; textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabClickListener == null || tabClickListener.onTabClick(position)) { viewPager.setCurrentItem(position); } } }); tabs.add(textView); tabContainer.addView(textView); } }
From source file:edu.ksu.cs.a4vm.bse.EditCollections.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_collections); Intent i = getIntent();/*from w w w .j av a 2s .c o m*/ Bundle extras = i.getExtras(); ranchInfo = extras.getString("ranch"); grpId = extras.getString("GrpId"); String name = null; String dateColleted = null; TextView tvRanch = (TextView) findViewById(R.id.ranchName); TextView tvDate = (TextView) findViewById(R.id.ranchDate); TextView tvBull = (TextView) findViewById(R.id.editBulls); TextView tvExport = (TextView) findViewById(R.id.export); TextView tvEditGrp = (TextView) findViewById(R.id.editGrp); permission = ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); //TextView tvDelete = (TextView) findViewById(R.id.deleteGrp); if (ranchInfo != null) { dateColleted = ranchInfo.substring(0, ranchInfo.indexOf(":")); name = ranchInfo.substring(ranchInfo.indexOf(":") + 1, ranchInfo.length()); } tvRanch.setText(name); tvDate.setText(dateColleted); tvBull.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent goToMorph = new Intent(getApplicationContext(), BullGroup.class); Bundle items = new Bundle(); items.putString("ranch", ranchInfo); items.putString("grpId", grpId); goToMorph.putExtras(items); startActivity(goToMorph); } }); tvEditGrp.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent goToMorph = new Intent(getApplicationContext(), NewGroup.class); goToMorph.putExtra("grpKey", grpId); startActivity(goToMorph); } }); tvExport.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (permission != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user ActivityCompat.requestPermissions(EditCollections.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE); } else { File file; File root = Environment.getExternalStorageDirectory(); File dir = new File(root.getAbsolutePath() + "/bull_collections"); dir.mkdirs(); file = new File(dir, "Data.csv"); try { if (!file.exists()) { file.createNewFile(); } FileOutputStream out = null; out = new FileOutputStream(file); String head = Constant.CSV_HEADING; ArrayList<ArrayList> list = CreateCSV.getData(getApplicationContext(), grpId); if (Constant.morphHeaders != null) { for (int i = 0; i < Constant.morphHeaders.size(); i++) { head = head + Constant.morphHeaders.get(i) + ","; } } out.write(head.getBytes()); if (list != null) { for (int i = 0; i < list.size(); i++) { out.write("\n".getBytes()); ArrayList<String> row = list.get(i); String contents; if (row != null) { contents = row.get(0); for (int j = 1; j < 103; j++) { contents = contents + "," + row.get(j); } out.write(contents.getBytes()); } } } out.close(); } catch (IOException e) { Log.e(Constant.CSV_MSG, "File writing error"); e.printStackTrace(); } Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Exported file"); sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); sendIntent.setType("text/html"); startActivityForResult(sendIntent, 119); } //if (root.canWrite()){ //} /*else { Toast.makeText(getApplicationContext(),"Failed to mount dir!",Toast.LENGTH_SHORT).show(); }*/ } }); }
From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java
private void configureEndDate(View view) { TextView endDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_end_date); endDateTextView.setEnabled(isThisHoursRecordNotActive()); if (isThisHoursRecordActive()) { endDateTextView.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null)); } else {/*from w ww .jav a2s .co m*/ endDateTextView .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null)); } endDateTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fragmentManager = getFragmentManager(); // If there is already a Date displayed, use that. Date dateToUse = (mHours.getEnd() == null) ? new Date() : mHours.getEnd(); DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse, "End", DateTimePickerFragment.BOTH); datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_END_DATE_PICKER); datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG); } }); if (mHours.getEnd() != null) { LocalDateTime endDateTime = new LocalDateTime(mHours.getEnd().getTime()); endDateTextView.setText(endDateTime.toString(DATE_FORMAT_PATTERN)); } }
From source file:com.softminds.matrixcalculator.dialog_activity.FunctionMaker.java
@Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false); if (isDark)/* w w w . j a v a2 s.c o m*/ setTheme(R.style.AppThemeDarkDialog); else setTheme(R.style.AppThemeDialog); super.onCreate(savedInstanceState); setContentView(R.layout.activity_function_maker); //Grab all Control References Button proceed = findViewById(R.id.ConfirmMakeFunction); final NumberPicker expo = findViewById(R.id.FunctionMakerExponent); final NumberPicker deg = findViewById(R.id.FunctionMakerDegree); final EditText coefficient = findViewById(R.id.MainCoefficientFiller); //Put Properties to Number Picker expo.setValue(1); expo.setMinValue(1); expo.setMaxValue(9); deg.setMinValue(1); deg.setMaxValue(7); deg.setValue(1); //Grab Default References final TextView ConstSign = findViewById(R.id.ConstantSign); final TextView FirstAuto = findViewById(R.id.FirstXAuto); FirstAuto.setText(ConvertToExponent(getString(R.string.X))); final TextView Const = findViewById(R.id.ConstantValueFunction); //Grab all Inactive TextViews final TextView Term1 = findViewById(R.id.CreatedXAuto1); Term1.setText(null); Term1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term1; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term2 = findViewById(R.id.CreatedXAuto2); Term2.setText(null); Term2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term2; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term3 = findViewById(R.id.CreatedXAuto3); Term3.setText(null); Term3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term3; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term4 = findViewById(R.id.CreatedXAuto4); Term4.setText(null); Term4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term4; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term5 = findViewById(R.id.CreatedXAuto5); Term5.setText(null); Term5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term5; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); final TextView Term6 = findViewById(R.id.CreatedXAuto6); Term6.setText(null); Term6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Term6; CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); //All Inactive Signs and Setting Click to Change Sign final TextView Sign1 = findViewById(R.id.AutoSign1); Sign1.setText(null); Sign1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign1); } }); final TextView Sign2 = findViewById(R.id.AutoSign2); Sign2.setText(null); Sign2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign2); } }); final TextView Sign3 = findViewById(R.id.AutoSign3); Sign3.setText(null); Sign3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign3); } }); final TextView Sign4 = findViewById(R.id.AutoSign4); Sign4.setText(null); Sign4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign4); } }); final TextView Sign5 = findViewById(R.id.AutoSign5); Sign5.setText(null); Sign5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign5); } }); final TextView Sign6 = findViewById(R.id.AutoSign6); Sign6.setText(null); Sign6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(Sign6); } }); //Set Click Listener to each deg.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int i) { //Degree maker will be here switch (numberPicker.getValue()) { case 7: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term6.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign6.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.X))); Sign3.setText("+"); Term4.setText(ConvertToExponent(getString(R.string.X))); Sign4.setText("+"); Term5.setText(ConvertToExponent(getString(R.string.X))); Sign5.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); break; case 6: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term5.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign5.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.X))); Sign3.setText("+"); Term4.setText(ConvertToExponent(getString(R.string.X))); Sign4.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Sign6.setText(null); Term6.setText(null); break; case 5: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term4.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign4.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.X))); Sign3.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Term5.setText(null); Term6.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 4: Term2.setText(ConvertToExponent(getString(R.string.X))); Sign2.setText("+"); Term3.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign3.setText("+"); Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 3: Term1.setText(ConvertToExponent(getString(R.string.X))); Sign1.setText("+"); Term2.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign2.setText("+"); Term3.setText(null); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign3.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 2: Term1.setText(ConvertToExponent(getString(R.string.NewX) + String.valueOf(deg.getValue()))); Sign1.setText("+"); Term2.setText(null); Term3.setText(null); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign2.setText(null); Sign3.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; case 1: Term1.setText(null); Sign1.setText(null); Term2.setText(null); Term3.setText(null); Term4.setText(null); Term5.setText(null); Term6.setText(null); Sign2.setText(null); Sign3.setText(null); Sign4.setText(null); Sign5.setText(null); Sign6.setText(null); break; } } }); expo.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int i) { if (CurrentTermCoefficient != null) { if (CurrentTermCoefficient.getText().toString().contains("x")) { String order = CurrentTermCoefficient.getText().toString(); String SubString = order.substring(0, order.indexOf("x") + 1); //Get Everything except from Exponent String SubString2 = SubString + String.valueOf(numberPicker.getValue()); CurrentTermCoefficient.setText(ConvertToExponent(SubString2)); } } else { Toast.makeText(getApplicationContext(), R.string.Warning12, Toast.LENGTH_SHORT).show(); numberPicker.setValue(2); } } }); //EditText KeyChange Listener coefficient.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (CurrentTermCoefficient == null) { Toast.makeText(getApplicationContext(), R.string.Warning12, Toast.LENGTH_SHORT).show(); return true; } else { if (CurrentTermCoefficient.getText().toString().contains("x")) { String res = coefficient.getText().toString() + "x" + String.valueOf(expo.getValue()); CurrentTermCoefficient.setText(ConvertToExponent(res)); } else CurrentTermCoefficient.setText(coefficient.getText().toString()); return false; } } }); //default Changers ConstSign.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SignChanger(ConstSign); } }); //default Coefficient FirstAuto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = FirstAuto; FirstAuto.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); //Constant changer Const.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { coefficient.setText(null); if (CurrentTermCoefficient != null) { if (isDark) CurrentTermCoefficient.setBackgroundColor( ContextCompat.getColor(getApplicationContext(), R.color.DarkcolorPrimaryDark)); else CurrentTermCoefficient .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); } CurrentTermCoefficient = Const; Const.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.cardColor)); } }); //SetterListener proceed.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Function EndUserCreation = GetMainFunction(deg.getValue(), Float.parseFloat(Const.getText().toString()), SignReturner(ConstSign)); ((GlobalValues) getApplication()).SendToGlobal(EndUserCreation); Log.d("Function is :", EndUserCreation.toString()); setResult(1452); finish(); } }); }
From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothTabView.java
/** * ??tab.// w w w .j a v a 2 s. co m * * @param tabText the tab text * @param fragment the fragment */ public void addItemView(String tabText, Fragment fragment) { tabItemTextList.add(tabText); pagerItemList.add(fragment); tabItemList.clear(); mTabLayout.removeAllViews(); for (int i = 0; i < tabItemTextList.size(); i++) { final int index = i; String text = tabItemTextList.get(i); TextView tv = new TextView(this.context); tv.setTextColor(tabColor); tv.setTextSize(tabTextSize); tv.setText(text); tv.setGravity(Gravity.CENTER); tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1)); tv.setPadding(12, 5, 12, 5); tv.setFocusable(false); tabItemList.add(tv); mTabLayout.addView(tv); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mViewPager.setCurrentItem(index); } }); } //? AbLogUtil.d(AbSlidingSmoothTabView.class, "addItemView finish"); mFragmentPagerAdapter.notifyDataSetChanged(); mViewPager.setCurrentItem(0); computeTabImg(0); }
From source file:com.bangqu.eshow.view.sliding.ESSlidingSmoothTabView.java
/** * ??tab.//from w ww. j a v a 2s . co m * * @param tabText the tab text * @param fragment the fragment */ public void addItemView(String tabText, Fragment fragment) { tabItemTextList.add(tabText); pagerItemList.add(fragment); tabItemList.clear(); mTabLayout.removeAllViews(); for (int i = 0; i < tabItemTextList.size(); i++) { final int index = i; String text = tabItemTextList.get(i); TextView tv = new TextView(this.context); tv.setTextColor(tabColor); tv.setTextSize(tabTextSize); tv.setText(text); tv.setGravity(Gravity.CENTER); tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1)); tv.setPadding(12, 5, 12, 5); tv.setFocusable(false); tabItemList.add(tv); mTabLayout.addView(tv); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mViewPager.setCurrentItem(index); } }); } //? ESLogUtil.d(ESSlidingSmoothTabView.class, "addItemView finish"); mFragmentPagerAdapter.notifyDataSetChanged(); mViewPager.setCurrentItem(0); computeTabImg(0); }
From source file:dev.datvt.cloudtracks.sound_cloud.LocalTracksFragment.java
public void showChangeLangDialog() { final Dialog dialog = new Dialog(ctx); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false);//from w ww. j a v a 2 s . c o m dialog.setContentView(R.layout.dialog_create_playlist); final EditText edt = (EditText) dialog.findViewById(R.id.edtInput); final TextView btnCreate = (TextView) dialog.findViewById(R.id.btnCreate); final TextView btnCancel = (TextView) dialog.findViewById(R.id.btnCancel); final ImageView btnDel = (ImageView) dialog.findViewById(R.id.btnDel); btnCreate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ret = edt.getText().toString(); if (ret != null && !ret.isEmpty()) { try { ToolsHelper.createPlaylist(ctx, ret); setUpListPlaylist(); Log.d("CREATE_2", "COMPLETE"); } catch (Exception e) { e.printStackTrace(); } } else { ToolsHelper.toast(ctx, getString(R.string.info_not_name_playlist)); showChangeLangDialog(); } dialog.dismiss(); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ret = null; dialog.cancel(); } }); btnDel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { edt.setText(""); } }); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); }
From source file:com.jet.sweettips.snackbar.SweetSnackbar.java
/** * Set the action to be displayed in this {@link SweetSnackbar}. * * @param text Text to display//from w w w. ja v a 2s . c o m * @param listener callback to be invoked when the action is clicked */ @NonNull public SweetSnackbar setAction(CharSequence text, final View.OnClickListener listener) { final TextView tv = mView.getActionView(); if (TextUtils.isEmpty(text) || listener == null) { tv.setVisibility(View.GONE); tv.setOnClickListener(null); } else { tv.setVisibility(View.VISIBLE); tv.setText(text); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { listener.onClick(view); // Now dismiss the SweetSnackbar dispatchDismiss(Callback.DISMISS_EVENT_ACTION); } }); } return this; }
From source file:android.support.designox.widget.Snackbar.java
/** * Set the action to be displayed in this {@link Snackbar}. * * @param text Text to display//from w w w. ja v a 2 s . c o m * @param listener callback to be invoked when the action is clicked */ @NonNull public Snackbar setAction(CharSequence text, final View.OnClickListener listener) { final TextView tv = mView.getActionView(); if (TextUtils.isEmpty(text) || listener == null) { tv.setVisibility(View.GONE); tv.setOnClickListener(null); } else { tv.setVisibility(View.VISIBLE); tv.setText(text); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { listener.onClick(view); // Now dismiss the Snackbar dispatchDismiss(Callback.DISMISS_EVENT_ACTION); } }); } return this; }
From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java
/** * Refreshes funds table with fetched data * * @param response JSONObject with funds data *//*from ww w. ja va 2 s. c o m*/ private void refreshFunds(JSONObject response) { try { if (response == null) { Toast.makeText(getActivity(), getResources().getString(R.string.GeneralErrorText), Toast.LENGTH_LONG).show(); return; } String notificationText; if (response.getInt("success") == 1) { View.OnClickListener fillAmount = new View.OnClickListener() { @Override public void onClick(View v) { ScrollView scrollView = (ScrollView) getView(); if (scrollView != null) { EditText tradeAmount = (EditText) scrollView.findViewById(R.id.TradeAmount); tradeAmount.setText(((TextView) v).getText()); scrollView.smoothScrollTo(0, scrollView.findViewById(R.id.tradingSection).getBottom()); } } }; notificationText = getResources().getString(R.string.FundsInfoUpdatedtext); TableLayout fundsContainer = (TableLayout) getView().findViewById(R.id.FundsContainer); fundsContainer.removeAllViews(); JSONObject funds = response.getJSONObject("return").getJSONObject("funds"); JSONArray fundsNames = response.getJSONObject("return").getJSONObject("funds").names(); List<String> arrayList = new ArrayList<>(); for (int i = 0; i < fundsNames.length(); i++) { arrayList.add(fundsNames.getString(i)); } Collections.sort(arrayList); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1); for (String anArrayList : arrayList) { TableRow row = new TableRow(getActivity()); TextView currency = new TextView(getActivity()); TextView amount = new TextView(getActivity()); currency.setText(anArrayList.toUpperCase(Locale.US)); amount.setText(funds.getString(anArrayList)); currency.setLayoutParams(layoutParams); currency.setTypeface(Typeface.DEFAULT, Typeface.BOLD); currency.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); currency.setGravity(Gravity.CENTER); amount.setLayoutParams(layoutParams); amount.setGravity(Gravity.CENTER); amount.setOnClickListener(fillAmount); row.addView(currency); row.addView(amount); fundsContainer.addView(row); } } else { notificationText = response.getString("error"); } mCallback.makeNotification(ConstantHolder.ACCOUNT_INFO_NOTIF_ID, notificationText); } catch (JSONException e) { e.printStackTrace(); } }