Jetpack Compose:TextField 可点击不起作用

时间:2021-06-09 11:04:09

标签: android android-jetpack-compose

出于某种原因,Compose TextField 的点击侦听器对我不起作用。

@Composable
    private fun ExposedDropdown(
        modifier: Modifier,
        list: List<String>,
        priority: Int
    ) {
        var expanded by remember { mutableStateOf(false) }
        Column(modifier) {
            OutlinedTextField(
                value = list[priority],
                onValueChange = { },
                readOnly = true,
                singleLine = true,
                label = { Text(stringResource(id = R.string.status)) },
                modifier = Modifier
                    .fillMaxWidth()
                    .clickable { Timber.i("Not working :(") }
                    .onFocusChanged { if (it.isFocused) expanded = !expanded },
                trailingIcon = {
                    Icon(
                        imageVector = Icons.Outlined.ArrowDropDown,
                        contentDescription = null,
                        modifier = Modifier
                            .clickable { expanded = !expanded }
                            .padding(16.dp)
                    )
                }
            )
            DropdownMenu(
                expanded = expanded,
                onDismissRequest = { expanded = false }
            ) {
                list.forEach { label ->
                    DropdownMenuItem(onClick = {
                        viewModel.setPriority(list.indexOf(label))
                        expanded = false
                    }) {
                        Text(text = label)
                    }
                }
            }
        }
    }

如您所见,我使用 onFocusChanged 提出了糟糕的解决方案,但效果不佳。

对于那些需要上下文的人,我正在尝试使用 ExposedDropdown,但我希望在单击 TextField 上的任意位置时将其打开

1 个答案:

答案 0 :(得分:1)

from pyspark_spy import ContextSparkListener, register_listener listener = ContextSparkListener() register_listener(spark_context, listener) with listener as events: df = spark.read.csv("inputfile.csv") spark.write.csv("outputfile.csv") print("Read statistics: ", listener.stage_input_metrics_aggregate()) print("Write statistics: ", listener.stage_output_metrics_aggregate()) >>> Read statistics: InputMetrics(bytesRead=140129708, recordsRead=271502) >>> Write statistics: OutputMetrics(bytesWritten=136828555, recordsWritten=265106) 修饰符当前 (clickable) 不适用于 1.0.0-beta08

这是一种解决方法,而不是真正的解决方案。
由于您的 TextField 是只读的,您可以使用第二个 TextFieldOutlinedTextField 包裹在 Box 中来处理点击。

Box