BlacKCaT27 / CurrencyEditText

A module designed to encapsulate the use of an Android EditText field for gathering currency information from a user. Supports all ISO-3166 compliant locales/currencies.
Apache License 2.0
339 stars 79 forks source link

CurrencyEditText setSelection problem #53

Open yeulucay opened 5 years ago

yeulucay commented 5 years ago

Hi, I am trying to place the cursor rightmost position at the first focus. I get the content length correctly and call setSelection method. But doesn't work for me.

binding.cet.setSelection(binding.cet.getText().length()); // I call it on focus

BlacKCaT27 commented 5 years ago

The cursor should automatically force itself to the rightmost position by default, so you shouldn't have to call set selection. What behavior are you seeing?

On Wed, Apr 17, 2019, 11:24 AM Yunus Emre Uluçay notifications@github.com wrote:

Hi, I am trying to place the cursor rightmost position at the first focus. I get the content length correctly and call setSelection method. But doesn't work for me.

binding.cet.setSelection(binding.cet.getText().length()); // I call it on focus

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BlacKCaT27/CurrencyEditText/issues/53, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_54XXsOTX0SJ7liZJ-ODy6WxZvR9Frks5vhzzKgaJpZM4c1VOr .

yeulucay commented 5 years ago

First of all, thank you for your fast response. I aligned the text to the right position. And when I touch the input, the cursor is placed onto the 0 position (leftmost) and value changes different. Let me explain; I will text 1,2,3. and it is expected to be $1.23 but,

BlacKCaT27 commented 5 years ago

Can you include the code you're using to set up the view? Something seems like it's not being initialized correctly. That's not how the view should be working

On Wed, Apr 17, 2019, 11:39 AM Yunus Emre Uluçay notifications@github.com wrote:

First of all, thank you for your fast response. I aligned the text to the right position. And when I touch the input, the cursor is placed onto the 0 position (leftmost) and value changes different. Let me explain; I will text 1,2,3. and it is expected to be $1.23 but,

  • $|0.00 (content aligned to right) I touched and cursor on the 0 position
  • $|10.00 here, cursor goes rightmost automatically $10.00|
  • $100.02|
  • $1000.23 final result.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/BlacKCaT27/CurrencyEditText/issues/53#issuecomment-484144363, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_54VUYZt9DvlI6DSfEWTE2YLAfjTu-ks5vh0BNgaJpZM4c1VOr .

yeulucay commented 5 years ago

I think, it works very well except one thing. The content text of the input is aligned left by default. So, when you touch (focus) to the input, the cursor takes place at the rightmost position by default. And after all changes, the input re-place the cursor to the end everytime. But only exception is, when you set gravity=end, it aligns the content text to the end of the input. And, when you touch (focus) the input, it places the cursor the the head. I mean, you should align the cursor to the rightmost when the first focus.

<com.blackcat.currencyedittext.CurrencyEditText android:id="@+id/ceCharge" style="@style/EditTextStyle" android:layout_width="match_parent" android:layout_height="50dp" android:gravity="end" !!!! HERE aligns content text to the end (this is what I need) android:inputType="numberDecimal" android:paddingStart="15dp" android:paddingEnd="15dp" android:textSize="20sp" />

BlacKCaT27 commented 5 years ago

Aha! So yes, that's a bug then. No eta if/when I'll be able to get to it. I'm able to help support the library via email but it's been admittedly too long since I've had time to work on the code itself.

If you can come up with a solution that doesn't change the behavior when gravity is not involved, please feel free to submit a PR.

On Wed, Apr 17, 2019, 11:50 AM Yunus Emre Uluçay notifications@github.com wrote:

I think, it works very well except one thing. The content text of the input is aligned left by default. So, when you touch (focus) to the input, the cursor takes place at the rightmost position by default. And after all changes, the input re-place the cursor to the end everytime. But only exception is, when you set gravity=end, it aligns the content text to the end of the input. And, when you touch (focus) the input, it places the cursor the the head. I mean, you should align the cursor to the rightmost when the first focus.

<com.blackcat.currencyedittext.CurrencyEditText android:id="@+id/ceCharge" style="@style/EditTextStyle" android:layout_width="match_parent" android:layout_height="50dp" android:gravity="end" !!!! HERE aligns content text to the end (this is what I need) android:inputType="numberDecimal" android:paddingStart="15dp" android:paddingEnd="15dp" android:textSize="20sp" />

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/BlacKCaT27/CurrencyEditText/issues/53#issuecomment-484148779, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_54a5SCVIPAXYLbI2s9Z_fqEQ0dypOks5vh0LVgaJpZM4c1VOr .