android - Making ListView Clickable React Native
问题描述
I am trying to make my ListView
clickable so that whenever the user clicks anywhere on the screen. An item is added to the list. Now the problem I am facing is that the listview is not scrolling.
So to solve this issue I wrapped my ListView
with TouchableWithoutFeedback
to make the screen clickable but unfortunately it cant be scrolled.
So to solve the scrolling issue I wrapped the whole thing under ScrollView
. But the problem now I am facing is that since during the start only 1 item is there in the listview so the whole screen isn't clickable only that small portion is that the 1 item takes on the screen is clickable.
Is there a solution to this problem?
<ScrollView>
<Screen
onStartShouldSetResponder={() => true}
style={{
flex: 1
}}
>
<TouchableOpacity
style={{ flex: 1 }}
onPress={() => this.addMessage()}
>
<ListView
data={this.state.readMessages}
renderRow={this.renderRow}
scrollEnabled={true}
/>
</TouchableOpacity>
</Screen>
</ScrollView>
This is what I ended up in the end.
解决方案
您可以在使用 ListView 时删除 scrollView。
<TouchableOpacity
style={{ flex: 1 }}
onPress={() => this.addMessage()}
>
<ScrollView>
<Screen
onStartShouldSetResponder={() => true}
style={{
flex: 1
}}
>
<ListView
data={this.state.readMessages}
renderRow={this.renderRow}
scrollEnabled={true}
/>
</Screen>
</ScrollView>
</TouchableOpacity>
你可以试试上面的代码。还有一件事,ListView已被弃用。您可以使用FlatList。
推荐阅读
- javascript - 如何在实时聊天或机器人聊天中启用音频音效?
- authentication - NetSuite SuiteTalk 令牌身份验证:登录尝试无效
- javascript - 未捕获(承诺中)错误:意外的令牌 < 更新打字稿类型定义
- javascript - 在三个js中用颜色填充线条之间的区域
- python - 为什么,在浮点运算中,0.9999999999999999 !=1 但 0.9999999999999999 + 1 == 2
- php - 为前 3 个帖子添加单独的课程 - Wordpress
- spring - 不查询同一张表时如何使用@formula
- dynamics-crm - If 语句获取不同的属性 - fetchXML
- ios - AR 参考组 - 图像的直方图狭窄或分布不均
- corda - 如何在 Corda 中为具有不同 jar 的不同节点创建多个流?