Example usage for android.widget TextView getText

List of usage examples for android.widget TextView getText

Introduction

In this page you can find the example usage for android.widget TextView getText.

Prototype

@ViewDebug.CapturedViewProperty
public CharSequence getText() 

Source Link

Document

Return the text that TextView is displaying.

Usage

From source file:com.fullmeadalchemist.mustwatch.ui.log.form.LogFormFragment.java

private void initClickListeners() {
    TextView dateField = getActivity().findViewById(R.id.createDateDate);
    if (dateField != null) {
        dateField.setOnClickListener(v -> {
            Log.i(TAG, "Date was clicked!");
            DialogFragment newFragment = new DatePickerFragment();
            Bundle args = new Bundle();
            args.putInt(YEAR, viewModel.logEntry.entryDate.get(Calendar.YEAR));
            args.putInt(MONTH, viewModel.logEntry.entryDate.get(Calendar.MONTH));
            args.putInt(DAY_OF_MONTH, viewModel.logEntry.entryDate.get(Calendar.DAY_OF_MONTH));
            newFragment.setArguments(args);
            newFragment.setTargetFragment(this, DATE_REQUEST_CODE);
            newFragment.show(getActivity().getSupportFragmentManager(), "datePicker");
        });//w w w . j a va 2  s  .c  om
    }

    TextView timeField = getActivity().findViewById(R.id.createDateTime);
    if (timeField != null) {
        timeField.setOnClickListener(v -> {
            Log.i(TAG, "Time was clicked!");
            DialogFragment newFragment = new TimePickerFragment();
            Bundle args = new Bundle();
            args.putInt(HOUR, viewModel.logEntry.entryDate.get(Calendar.HOUR));
            args.putInt(MINUTE, viewModel.logEntry.entryDate.get(Calendar.MINUTE));
            newFragment.setArguments(args);
            newFragment.setTargetFragment(this, TIME_REQUEST_CODE);
            newFragment.show(getActivity().getSupportFragmentManager(), "timePicker");
        });
    }

    Button submitButton = getActivity().findViewById(R.id.button_submit);
    if (submitButton != null) {
        submitButton.setOnClickListener(v -> {
            Log.i(TAG, "Submit button clicked!");

            TextView phTv = getActivity().findViewById(R.id.ph);
            if (phTv != null) {
                viewModel.logEntry.acidity = toFloat(phTv.getText().toString().trim());
            }

            TextView sgTv = getActivity().findViewById(R.id.sg);
            if (sgTv != null) {
                viewModel.logEntry.sg = toFloat(sgTv.getText().toString().trim());
            }

            TextView noteTv = getActivity().findViewById(R.id.notes);
            if (noteTv != null) {
                viewModel.logEntry.note = noteTv.getText().toString().trim();
            }

            viewModel.saveNewLogEntry();
            navigationController.navigateToBatchDetail(this.batchId);
        });
    }
}

From source file:cl.ipp.katbag.fragment.Worlds.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) super.getActivity();
    v = inflater.inflate(R.layout.fragment_worlds, container, false);
    mainActivity.supportInvalidateOptionsMenu();

    // rescues parameters
    Bundle bundle = getArguments();/*from   ww  w  .  j a v  a  2s  .  c  o  m*/
    if (bundle != null) {
        id_app = bundle.getLong("id_app");
    }

    notRegister = (TextView) v.findViewById(R.id.world_not_register);
    editMode = false;
    loadListView();

    worldsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!editMode) {
                TextView idWorld = (TextView) view.findViewById(R.id.world_row_id);

                Bundle bundle = new Bundle();
                bundle.putLong("id_world", Long.valueOf(idWorld.getText().toString()));
                bundle.putString("name_world", idWorld.getText().toString());

                mFragment = new OneWorld();
                mFragment.setArguments(bundle);
                FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
                t.replace(R.id.fragment_main_container, mFragment);
                t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                t.addToBackStack(mFragment.getClass().getSimpleName());
                t.commit();
            }
        }
    });

    return v;
}

From source file:net.bible.android.view.util.widget.BookmarkStyleAdapterHelper.java

public void styleView(TextView view, BookmarkStyle bookmarkStyle, Context context, boolean overrideText,
        boolean centreText) {

    // prepare text to be shown
    String baseText;//ww w . j a v a 2 s  . com
    if (overrideText) {
        baseText = sampleText;
    } else {
        baseText = view.getText().toString();
        // avoid multiple *'s
        if (baseText.startsWith("*")) {
            StringUtils.strip(baseText, "*");
        }
    }

    int backgroundColor = Color.WHITE;
    switch (bookmarkStyle) {
    case YELLOW_STAR:
        backgroundColor = UiUtils.getThemeBackgroundColour(context);
        view.setTextColor(UiUtils.getThemeTextColour(context));
        CharSequence imgText = addImageAtStart("* " + baseText, R.drawable.goldstar16x16, context);
        view.setText(imgText, TextView.BufferType.SPANNABLE);
        break;
    case RED_HIGHLIGHT:
        backgroundColor = BookmarkStyle.RED_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    case YELLOW_HIGHLIGHT:
        backgroundColor = BookmarkStyle.YELLOW_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    case GREEN_HIGHLIGHT:
        backgroundColor = BookmarkStyle.GREEN_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    case BLUE_HIGHLIGHT:
        backgroundColor = BookmarkStyle.BLUE_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    }
    view.setBackgroundColor(backgroundColor);
    view.setHeight(CommonUtils.convertDipsToPx(30));
    if (centreText) {
        view.setGravity(Gravity.CENTER);
    }
}

From source file:com.bangz.shotrecorder.RecordDetailActivity.java

private void setShareIntent() {

    if (mShareActionProvider != null) {

        final TextView viewNumber = (TextView) findViewById(R.id.txtNumber);
        String strnumber = viewNumber.getText().toString();

        final TextView viewTime = (TextView) findViewById(R.id.txtTime);
        String strTime = viewTime.getText().toString();

        final TextView viewDate = (TextView) findViewById(R.id.txtDate);
        String strDate = viewDate.getText().toString();

        final TextView viewdescription = (TextView) findViewById(R.id.txtDescription);
        String strDescription = viewdescription.getText().toString();

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        String strcontent = String.format(getResources().getString(R.string.share_content), strDescription,
                strnumber, strTime, strDate);
        intent.putExtra(Intent.EXTRA_TEXT, strcontent);
        mShareActionProvider.setShareIntent(intent);
    }/*ww  w . j a v a 2 s.c om*/

}

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

@Override
public boolean onTouch(View v, MotionEvent event) {
    // when the user touches an item, onTouch is called for action down and again for action up
    // we only want to do something on one of those actions. event tells us which action.
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // onTouch is passed the textview's parent view, a linearlayout - what we set the
        // event on. Look at its children to find the textview
        if (v instanceof android.widget.LinearLayout) {
            android.widget.LinearLayout layView = (android.widget.LinearLayout) v;
            // the layout (from list_item.xml should only have one child, but, here's how
            // you find the children of a layout or other view group.
            for (int i = 0; i <= layView.getChildCount(); i++) {
                if (layView.getChildAt(i) instanceof TextView) {
                    // keep track of TV stuff was most recently touched to un-highlighted
                    if (currSelection != null) {
                        currSelection.setBackgroundColor(parent.getResources().getColor(R.color.light_blue));
                    }/* www .  j a v  a 2 s. c o  m*/
                    TextView tmp = ((TextView) layView.getChildAt(i));
                    currSelection = tmp;
                    parent.setSelectedStuff(tmp.getText().toString());
                    // create an intent (in the name of the parent activity) to start the WebViewActivity
                    // pass the web view activity two strings: the url and the name of the selected item.
                    // expect the WebViewActivity to return a result, which will be picked up in the
                    // requesting activity -- MainActivity.
                    Intent movieDetails = new Intent(parent, MovieDetails.class);
                    //                        movieDetails.putExtra("MovieLibrary",(parent.movieLibrary));
                    movieDetails.putExtra("movieName", ((TextView) layView.getChildAt(i)).getText().toString());
                    //                        try {
                    //                            movieDetails.putExtra("genreName", getGenre(((TextView) layView.getChildAt(i)).getText().toString()));
                    //                        } catch (JSONException e) {
                    //                            e.printStackTrace();
                    //                        };
                    parent.startActivity(movieDetails);
                }
            }
        }
        // code below should never executes. onTouch is called for textview's linearlayout parent
        if (v instanceof TextView) {
            android.util.Log.d(this.getClass().getSimpleName(),
                    "in onTouch called for: " + ((TextView) v).getText());
        }
    }
    return true;
}

From source file:cl.ipp.katbag.fragment.Drawings.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) super.getActivity();
    v = inflater.inflate(R.layout.fragment_drawings, container, false);
    mainActivity.supportInvalidateOptionsMenu();

    // rescues parameters
    Bundle bundle = getArguments();/*  w w  w. j ava 2  s.  co m*/
    if (bundle != null) {
        id_app = bundle.getLong("id_app");
        type_app = bundle.getString("type_app");
    }

    notRegister = (TextView) v.findViewById(R.id.drawings_not_register);
    editMode = false;
    loadListView();

    drawingsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!editMode) {
                TextView idDrawing = (TextView) view.findViewById(R.id.drawing_row_id);

                Bundle bundle = new Bundle();
                bundle.putLong("id_drawing", Long.valueOf(idDrawing.getText().toString()));
                bundle.putString("name_drawing", idDrawing.getText().toString());
                bundle.putString("type_app", type_app);

                mFragment = new OneDrawing();
                mFragment.setArguments(bundle);
                FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
                t.replace(R.id.fragment_main_container, mFragment);
                t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                t.addToBackStack(mFragment.getClass().getSimpleName());
                t.commit();
            }
        }
    });

    return v;
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentProduct.java

/**
 * In/decrease the value of the product count textview
 * @param button the button that was clicked
 * @param up in- or decrease//from  w  ww.j  a va  2s . c o  m
 */
private void changeProductCountText(View button, boolean up) {

    // get the parent view so we can reach the textview of this productrow only
    View clickedProductView = (View) button.getParent();
    if (clickedProductView != null) {

        // get the productcount textview
        TextView clickedProductText = (TextView) clickedProductView.findViewById(R.id.product_count);
        if (clickedProductText != null) {
            int clickedCount = Integer.valueOf(clickedProductText.getText().toString());
            if (!up && clickedCount > 0) {
                // decrease value, if larger then 0
                clickedProductText.setText(String.valueOf(clickedCount - 1));
            } else if (up && clickedCount < 99) {
                // increase value, if smaller then 99
                clickedProductText.setText(String.valueOf(clickedCount + 1));
            }
        }
    }
}

From source file:com.esri.android.maps.app.MapAppRobotiumTests.java

/**
 * Long press on the view to test reverse geocoding
 *//* w  w w . j  ava  2  s. c o  m*/

public void testReverseGeocode() {

    // Get the map view
    View mapView = solo.getView(id.map);
    Assert.assertTrue(solo.waitForView(mapView));

    // Trigger the reverse geocoding of screen location
    solo.clickLongOnView(mapView, 3000);
    solo.takeScreenshot("reverse_geocode");

    // Expect reverse geocoding to assign an
    // address to the text view
    TextView textView = (TextView) solo.getView(id.textView1);
    Assert.assertTrue(textView.getText().length() > 0);
    solo.takeScreenshot("reverse_geocode_results");
}

From source file:com.esri.android.maps.app.MapAppRobotiumTests.java

/**
 * Test searching by typing in address//  w w  w .  java2 s  .  co m
 */
public void testTypedAddress() {
    // Get the map view
    View mapView = solo.getView(id.map);
    Assert.assertTrue(solo.waitForView(mapView));

    // Get the text field for inputting place names or addresses
    final EditText searchText = solo.getEditText("Search", true);
    Assert.assertNotNull(searchText);

    // Use a local address near you...
    solo.typeText(searchText, solo.getString(string.localAddressNearYou));

    solo.sleep(4000);
    solo.pressSoftKeyboardSearchButton();
    // Wait for it...
    solo.sleep(9000);
    TextView result = (TextView) solo.getView(id.textView1);
    Assert.assertTrue(result.getText().length() > 0);
    solo.takeScreenshot("typed_address");
}

From source file:com.cloudbase.cbhelperdemo.FunctionScreen.java

@Override
public void onClick(View v) {
    TextView functionText = (TextView) this.getView().findViewById(R.id.functionCodeText);

    if (v.getId() == R.id.callFunctionButton) {
        // execute the cloudfunction
        MainActivity.helper.runCloudFunction(functionText.getText().toString(), null, this);
    }//from  ww  w  .  jav a  2s  .  c  o m

    if (v.getId() == R.id.callAppletButton) {
        // run the standard twitter search applet. This Fragment is also the responder and will display
        // a list of the results in an AlertDialog
        String appletCode = "cb_twitter_search";
        Map<String, String> params = new HashMap<String, String>();
        params.put("search", "#bgee");

        MainActivity.helper.runApplet(appletCode, params, this);
    }

    if (v.getId() == R.id.callPayPalButton) {
        CBPayPalBillItem billItem = new CBPayPalBillItem();
        billItem.setName("test paypal paymnet");
        billItem.setDescription("this is a test paypal bill for $9.99");
        billItem.setAmount(9.99);
        billItem.setTax(0);
        billItem.setQuantity(1);

        CBPayPalBill bill = new CBPayPalBill();
        bill.setName("test paypal bill");
        bill.setDescription("test papal bill for $9.99");
        bill.setCurrency("USD");
        bill.setInvoiceNumber("test-invoice-01");
        bill.setPaymentCancelledFunction("");
        bill.setPaymentCompletedFunction("");
        bill.addNewItem(billItem);

        MainActivity.helper.preparePayPalPurchase(bill, false, this);
    }
}