0

I have a HorizontalPager in my screen with 2 pages. Both contain one EditText. When I navigate from first page to second, the EditText in second page doesn't display any text (not even the hint) for sometime. Only when I type some characters and stop, the text appears and after that it works properly.

My code:

val pagerState = rememberPagerState(initialPage = 0)
HorizontalPager(count = 2, state = pagerState) {
    AndroidView(
        modifier = Modifier.width(200.dp),
        factory = { context ->
            AppCompatEditText(context).apply {
                hint = "Page $it"
            }
        }
    )
}

enter image description here

Maybe there is some problem in the way Horizontal Pager initially loads Composables for subsequent pages.

How can I fix this?

(I am not using TextField as it has some other nasty bugs)

Arpit Shukla
  • 9,612
  • 1
  • 14
  • 40
  • Hello, can you give us the full class where this code comes from ? – Quentin M Nov 10 '21 at 09:17
  • This is the full code. I am using Accompanist [HorizontalPager](https://google.github.io/accompanist/pager/#horizontalpager) here – Arpit Shukla Nov 10 '21 at 09:19
  • Why are you using an EditText from the older view system when Compose already has an EditText? – Johann Nov 10 '21 at 09:19
  • @Johann Mainly because of [this](https://stackoverflow.com/questions/69844103/how-to-remove-keyboard-flicker-when-switching-between-textfields) issue. – Arpit Shukla Nov 10 '21 at 09:21

0 Answers0