logo
down
shadow

Android : Multi line text EditText inside BottomSheetDialog


Android : Multi line text EditText inside BottomSheetDialog

Content Index :

Android : Multi line text EditText inside BottomSheetDialog
Tag : android , By : Pierre LeBoo
Date : November 28 2020, 11:01 PM

Does that help I have a bottom sheet dialog and exists EditText in layout. EditText is multiline, max lines is 3. I put : , Here is an easy way to do it.
yourEditTextInsideBottomSheet.setOnTouchListener(new OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
        v.getParent().requestDisallowInterceptTouchEvent(true);
        switch (event.getAction() & MotionEvent.ACTION_MASK){
        case MotionEvent.ACTION_UP:
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }
        return false;
   }
});

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Android: Vertical alignment for multi line EditText (Text area)


Tag : android , By : user176691
Date : March 29 2020, 07:55 AM
I hope this helps you . I want to have 5 lines for the height of the text area. I am using the following code. , Use android:gravity="top"

why is the EditText multi-line in android


Tag : android , By : meehan
Date : March 29 2020, 07:55 AM
I wish this help you You can use android:SingleLine
<EditText
    android:singleLine="true"
    ...
    ...

How to Get string text from multi line EditText


Tag : java , By : Dasharath Yadav
Date : March 29 2020, 07:55 AM
seems to work fine You have to move : st_text = data.getText().toString().trim(); after : int id = item.getItemId();
So ... your code should look like :
public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
st_text = data.getText().toString().trim();
        if (id == R.id.post) {
            if (TextUtils.isEmpty(st_text)){
                AlertDialog.Builder builder = new AlertDialog.Builder(CreatePostActivity.this,R.style.AlertDialog);
                String titleText = "Error \n  ";
                ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.colorPrimaryDark));
                SpannableStringBuilder ssBuilder = new SpannableStringBuilder(titleText);
                ssBuilder.setSpan(
                        foregroundColorSpan,
                        0,
                        titleText.length(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE
                );
                builder.setTitle(ssBuilder);
                builder.setCancelable(false);
                builder.setPositiveButton("OK", null);
                AlertDialog dialog = builder.create();
                dialog.setMessage("You can't create empty post");
                dialog.show();
                return false;
            }else {
                AlertDialog.Builder builder = new AlertDialog.Builder(CreatePostActivity.this,R.style.AlertDialog);
                builder.setTitle("Success");
                builder.setMessage("Your post is successfully created.");
                builder.setPositiveButton("OK", null);
                AlertDialog dialog = builder.create();
                dialog.show();
                return true;
            }
        }
        return super.onOptionsItemSelected(item);
    }

How to retrieve multi-line text from Edittext?


Tag : android , By : Puneet Madaan
Date : March 29 2020, 07:55 AM
hope this fix your issue After too much searching and waiting for an answer to this question. I have resolved this issue.
Solution: I have measured each and every line & words for preserve this as Multiline text, you can use below function for that.
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
float density = metrics.density;

String result = fitString(ipText, ipText.getText().toString());

private String fitString(EditText editText, String message) {

        Log.i(TAG, "fitString: Default String : " + message);

        StringBuilder finalMessage = new StringBuilder();

        if (isTooLarge(editText, message)) {
            Log.i(TAG, "fitString: isTooLarge 1 : " + true);
            List<String> lineList = Arrays.asList(message.split("\n"));
            Log.i(TAG, "fitString: stringList" + lineList);

            if (lineList != null && lineList.size() > 0) {

                for (int i = 0; i < lineList.size(); i++) {

                    if (lineList.get(i) != null && !lineList.get(i).isEmpty()) {

                        if (isTooLarge(editText, lineList.get(i))) {
                            Log.i(TAG, "fitString: isTooLarge 2 : " + lineList.get(i) + " == " + true);

                            List<String> wordList = Arrays.asList(lineList.get(i).split(" "));
                            Log.i(TAG, "fitString: wordList" + wordList);

                            if (wordList != null && wordList.size() > 0) {
                                Log.i(TAG, "fitString: wordList : " + wordList.size());

                                StringBuilder temp = new StringBuilder();
                                String lastWord = "";

                                for (int j = 0; j < wordList.size(); j++) {

                                    if (wordList.get(j) != null && !wordList.get(j).isEmpty()) {

                                        if (isTooLarge(editText, wordList.get(j))) {
                                            Log.i(TAG, "fitString: isTooLarge 3 : " + wordList.get(j) + " == " + true);
                                            String newString = fitCharacter(editText, wordList.get(j));
                                            Log.i(TAG, "fitString: fitCharacter == " + newString);

                                            if (j == (wordList.size() - 1) && i == (lineList.size() - 1)) {
                                                finalMessage.append(newString);
                                            } else {
                                                finalMessage.append(newString + "\n");
                                            }

                                        } else {

                                            if (j == 0) {
                                                lastWord = wordList.get(j);
                                            } else {
                                                lastWord = " " + wordList.get(j);
                                            }


                                            temp.append(lastWord);
                                            Log.i(TAG, "fitString: temp : " + temp);
                                            Log.i(TAG, "fitString: lastWord : " + lastWord);

                                            if (isTooLarge(editText, temp.toString())) {
                                                temp.setLength(0); // clear String Builder,  new StringBuilder()
                                                temp.append(lastWord);
                                                if (j == (wordList.size() - 1) && i != (lineList.size() - 1)) {
                                                    Log.i(TAG, "fitString: ###### 1");
                                                    finalMessage.append("\n" + lastWord.trim() + "\n");
                                                } else {
                                                    Log.i(TAG, "fitString: ###### 2");
                                                    finalMessage.append("\n" + lastWord.trim());
                                                }

                                            } else {

                                                if (j == (wordList.size() - 1) && i != (lineList.size() - 1)) {
                                                    Log.i(TAG, "fitString: ###### 3");
                                                    finalMessage.append(lastWord + "\n");
                                                } else {
                                                    Log.i(TAG, "fitString: ###### 4");
                                                    finalMessage.append(lastWord);
                                                }

                                            }

                                            Log.i(TAG, "fitString: finalMessage : " + finalMessage);
                                        }

                                    } else {
                                        Log.e(TAG, "fitString: Word is Null or Empty.");
                                        finalMessage.append(" ");
                                    }

                                }

                            } else {
                                Log.e(TAG, "fitString: wordList is Null or Empty.");
                            }


                        } else {
                            Log.i(TAG, "fitString: isTooLarge 2 : " + lineList.get(i) + " == " + false);
                            if (i == (lineList.size() - 1)) {
                                finalMessage.append(lineList.get(i));
                            } else {
                                finalMessage.append(lineList.get(i) + "\n");
                            }
                        }
                    } else {
                        Log.e(TAG, "fitString: Line is Null or Empty.");
                        finalMessage.append(lineList.get(i) + "\n");
                    }
                }
            } else {
                Log.e(TAG, "fitString: stringList is Null or Empty.");
                finalMessage.append("");
            }

            return finalMessage.toString();

        } else {
            Log.i(TAG, "fitString: isTooLarge : " + false);
            return message;
        }
    }

    public String fitCharacter(EditText editText, String message) {

        Log.i(TAG, "fitCharacter2: Default Word : " + message);

        StringBuilder finalWord = new StringBuilder();
        int startIndex = 0;
        int endIndex = 1;


        for (; ; ) {

            String tempSplitWord = message.substring(startIndex, endIndex);
            Log.i(TAG, "fitCharacter2: startIndex : " + startIndex + " endIndex : " + endIndex + " tempSplitWord : " + tempSplitWord);
            if (!isTooLarge(editText, tempSplitWord)) { // isTooLarge
                if (endIndex < message.length()) {
                    endIndex = endIndex + 1;
                    Log.i(TAG, "IF fitCharacter2: endIndex < message.length() " + endIndex + " < " + message.length());
                } else {
                    String result = finalWord.append(tempSplitWord).toString();
                    Log.i(TAG, "IF RETURN RESULT : " + result);
                    return result;
                }
            } else {
                endIndex = endIndex - 1;
                String splitWord = message.substring(startIndex, endIndex);
                Log.i(TAG, "ELSE fitCharacter2: startIndex : " + startIndex + " endIndex : " + endIndex + " splitWord : " + splitWord);

                boolean isTooLarge = isTooLarge(editText, splitWord);
                if (!isTooLarge) {
                    finalWord.append(splitWord + "\n");
                }
                startIndex = endIndex;
                endIndex = endIndex + 1;
                Log.i(TAG, "ELSE fitCharacter2: startIndex : " + startIndex + " endIndex : " + endIndex);
            }
        }
    }

    private boolean isTooLarge(EditText editText, String newText) {
        if (editText != null && editText.getPaint() != null) {
            float textWidth = editText.getPaint().measureText(newText);

            return (textWidth >= (editText.getMeasuredWidth() - (12 * density))); // editText.getMeasuredWidth();
        } else {
            return false;
        }
    }

Android BottomSheetDialog with EditText covered by keyboard


Tag : android , By : Tonci Grgin
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • "Android 2.x" vs "Google APIs" for Android AVD Setup
  • How to center buttons on screen horizontally and vertically plus equidistant apart?
  • Discrete seekbar in Android app?
  • Gradle Build Fails - Illegal exception table range in class file com/google/wireless/android/sdk/stats/GradleBuildMemory
  • register has type Long (High Half) but expected Long (Low Half)
  • Is it good idea to use Dispatcher.Main with delay( )?
  • WebView and Advanced View is Not loading partiucalr URL
  • How to show three dots at the end of text view
  • Is it possible to run macros within Android Studio project?
  • Adding a button with default appearance but changed background color
  • What is best way to show notification at a certain time in Android?
  • Jetifier not working when library uses android component and app uses androidx component
  • How can I write the contents of an image in a filesystem
  • Retrieve a list of images from the Database and display them using a ListView?
  • java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
  • Timer/hourglass wont stop
  • How can I make AndroidX the default library for new Android projects?
  • Is it okay to delete buildToolsVersion android studio because of a warning in the Asyncstorage library?
  • Can I call a class that doesn't have an activity withIntent?
  • Android TextView fontFamily not working when set via TextAppearance
  • Unable to find nearby places
  • Is there any way to launch my application right away without 'Ok Google"?
  • Places api set location biased based on current location
  • Layout Preview is not displaying layout when Material Design is added
  • How do I resolve this diamond problem in Kotlin?
  • How to update the custom value in a view model object
  • How to stop refreshing/re-creating activity when updating Firebase data using setValue?
  • Manifest Permissions vs App Setttings Permissions
  • NumberFormatException in Try-Catch while converting String to Int
  • How to pass observable fields through include tag?
  • Next button on Android keyboard not submitting form
  • Does Firestore support automatic functions for updates?
  • Why app crashing because of a missing dimension (for google maps) only when I apply changes?
  • How to make a grouping, ordering and sorting: Kotlin collection
  • how to use augmented reality to change the color of a qr code once it is detected using with arcore and ml kit firebase
  • how to resolve Firebase projects adding quota problem?
  • Why it Kotlin giving me the wrong Int value when converting from a String
  • How to add bottom navigation listeners to fragments
  • Why is scrollview hiding buttons behind other views?
  • Open Settings using Linking.sendIntent()
  • How do I access an unknown node in firebase while retrieving data?
  • Can't retrieve list of all users from firebase authetication
  • many activities with same content (adview, reward adview, functions...) how to avoid repeating code?
  • Popup doesn't hide when touch outside
  • proper way to handling images in Android? by using Firebase
  • Android: Button is faded gray when it should be transparent
  • Gradle DSL method not found: 'deleteAllActions()'
  • In Clean Architecture, must Repository is Android or Kotlin module?
  • Kotlin parse double from string
  • Inconsistency detected. Invalid view holder adapter positionViewHolder
  • In App Update API always returns 1 (UPDATE_NOT_AVAILABLE)
  • Event of ImageView when click
  • Basic precautions to prevent piracy?
  • What is the difference between 'center' and 'centerCrop' in the "ImageView"?
  • Unable to receive SIP calls when app is killed
  • Android emulator not processing http get request, but iOS simulator works fine
  • Android Problem with sharing temporary file
  • How to add Broadcast in Android?
  • How to hide 'Running in Chrome' toast on TWA application on Android devices?
  • How to Fix Error: Could not find method deleteAllActions() for arguments [] on task
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com