I have a problem with jetpack compose textfield and the keyboard autocomplete - textfield

While writing in a textfield in compose, when i write a sequence that look like "something.something".
Where "something" isn't a white space, the cursor behave strangely.
Here i enter a random word:
I add the "."
Here when i enter the new caracter like you can see bellow the word the the first caracter seems to be ignore by the autocorrect
When i enter the second caracter it is display before the last one
It continue continue like this
For the code :
val (title, setTitle) = remember { mutableStateOf ("")}
TextField(
Modifier = Modifier.padding(5.dp),
MaxLines = 1,
label = {Text(text = "Title")},
value = title,
onValueChange = setTitle,
)
And my compose version is '1.0.1'
i also try some compose samples like "jetchat" but they does the same thing.

It seems the problem came from my Galaxy S7 predictive text functionality when using the French keyboard. Once I change the keyboard to English or removed the predictive text functionality, it worked fine.

You should use rememberSaveable rather than remember

Related

How to change toast message's default icon in jetpack compose?

I have a toast message in my code and it shows when user enter empty dictionary name but there is a problem for me toast shows message with a default android icon and I don't want this. How can I change this icon or remove in jetpack compose kotlin ?
here is screen shot.
Hear is my code
fun updateDictionary(context: Context, dictionaryName: String): Boolean {
if (dictionaryName.isEmpty()) {
Toast.makeText(context, "Please Enter The Dictionary Name !", Toast.LENGTH_LONG).show()
return false
}
val dictionary = OwnDicEntity(dictionaryName, dicCreationTime ?: "", dicId)
updateDicUseCase.updateDic(dictionary)
return true
}
if I want to update dictionary , I go to the update screen and this function is triggered and I have to write update dictionary name if I enter empty dictionary name. it shows toast message as I wrote above.
I'm returning a boolean value, true and false, so that it doesn't update when I enter a empty value.
Starting with Android 12 you don't get any control over how Toasts look - you get two lines of text and your application icon, so the user knows where the Toast came from. (Android 11 still allows for a custom view, but only for apps in the foreground.)
If you want to change the icon, you need to add a new one for your app - the one you're seeing is the default ic_launcher drawable for a new project. Some info about that here.
If you want to remove the icon, you can't! Since you seem to be displaying this as a popup in your own app, you might want to consider a Snackbar instead, or setting the error hint on a text field, or maybe create an area of your UI dedicated to displaying any errors (e.g. if there are multiple components you need to validate, and you want the error state in one place).

Kotlin button listener

I want to increase the value of i every time the button is clicked
I've tried this code but it's not working.
val textview = findViewById<TextView>(R.id.texttest)
var i = 10
bookbutton.setOnClickListener {
i++
}
textview.text = "$i"
You have to set the text inside the listener:
bookbutton.setOnClickListener {
i++
textview.text = "$i"
}
Your listener is updating the value of i — but that's not having any visible effect because by then it's too late: the text shown in your textview has already been set.
Let's review the order of events:
Your code runs. That creates a text view and a variable, sets a listener on the button, and sets the text in the text view.
At some later point(s), the user might click on the button. That calls the listener, which updates the variable.
So while your code sets the listener, the listener does not run until later. It might not run at all, or it might run many times, depending on what the user does, but it won't run before you set the text in the text view.
So you need some way to update the text when you update the variable. The simplest way is to do explicitly it in the listener, e.g.:
bookbutton.setOnClickListener {
textview.text = "${++i}"
}
(There are other ways — for example, some UI frameworks provide ways to ‘bind’ variables to screen fields so that this sort of update happens automatically. But they tend to be a lot more complex; there's nothing wrong with the simple solution.)

how to set onClickListener on words of string in a textField in compose UI

Actually I'm developing an social-media app where I want that my user can mention more than one user in between of their compliment string just like in Instagram comment section...
on which if someOne tap of their username... it'll lead them to the particular user's profile
desired result example
I'm well aware of the use of buildAnnotationString{} where we can play with textStyle but is there anyway to set onClickListener
you have to create ClickableText not simple Text.
ClickableText(text = AnnotatedString("ClickableText"),
onClick = {
// perform here your action
},
)

RichEditBox : set a style only for the characters that are about to be written

I'm trying to create a simple text editor in a Windows 8 application, like a simple OneNote. I can set font size, font color and font style, but the problem is that it's applied to the whole content of my RichEditBox, even to the text that has already been written. But I would like that, when I select "Italic" for exemple, only the future characters should be written in Italic, and the words and characters already written remain in the style they were.
It's quite difficult to describe.
Do I use the good XAML element (RichEditBox) ? Is there a method to select the actual position of the writer in the RichEditBox ?
Thanks for your answers !
Try this button event. rebTextNote is RichEditBox object.
using Windows.UI.Text;
public void btnItalic_Click(object sender, RoutedEventArgs e)
{
ITextCharacterFormat format = rebTextNote.Document.Selection.CharacterFormat;
if (format.Italic != FormatEffect.On)
format.Italic = FormatEffect.On;
else
format.Italic = FormatEffect.Off;
}

How can I change text color in CEikRichTextEditor Symbian

Is there anyway to change parts of the text I add into CEikRichTextEditor control without selecting the text first - which shows the green selection rectangle over the text - and then apply text style?
Here is the code I use which gives an ugly and sloppy style when user see the running green selection rectangle over the text especially when I insert the text inside a loop
CDesCArray* temp = new(ELeave) CDesCArrayFlat(4);
temp->AppendL(_L("First"));
temp->AppendL(_L("Second"));
temp->AppendL(_L("Third"));
temp->AppendL(_L("Fourth"));
TBuf<100>iNumbers;
iNumbers.Copy(_L("Here is the numbers"));
iRichText1->SetTextL(&iNumbers); // iRichText1 is a pointer to CEikRichTextEditor object
for(TInt i = 0; i < temp->Count(); i++)
{
TInt x = iRichText1->Text()->DocumentLength();
iRichText1->RichText()->InsertL(x, (*temp)[i]);
iRichText1->SetSelectionL(x,iRichText1->Text()->DocumentLength());
iRichText1->BoldItalicUnderlineEventL(CEikGlobalTextEditor::EItalic);
TInt line = iRichText1->Text()->DocumentLength();
iRichText1->RichText()->InsertL(line, _L("\f\f"));
}
Many thanks in advance.
You need to operate on the CRichText object owned by the editor and apply a paragraph or character format over it (using ApplyCharFormatL() / ApplyParaFormatL()). This avoids any need to select text.
Example applying a paragraph format
Example applying a character format