作者:Aries小阳光 | 来源:互联网 | 2023-01-31 22:43
如何添加点击监听器Flatlist
?
我的代码:
renderItem({item, index}){
return
}
render(){
return();
}
}
更新1:我使用了按钮,但它没有工作Flatlist
.但是只使用按钮代替Flatlist
,它可以工作.为什么它在Flatlist
renderItem 中不起作用?
_listener = () => {
alert("clicked");
}
renderItem({item, index}){
return
}
Manish..
18
我用过TouchableWithoutFeedback
.为此,您需要将所有renderItem元素(即您的行)添加到TouchableWithoutFeedback
.然后添加onPress
事件并将FaltList项传递给onPress事件.
import {View, FlatList, Text, TouchableWithoutFeedback} from 'react-native';
render() {
return (
(
this.actionOnRow(item)}>
ID: {item.id}
Title: {item.title}
)}
/>
);
}
actionOnRow(item) {
console.log('Selected Item :',item);
}
Raj Suvariya..
11
您需要将行元素(在renderItem方法内部)包装在
标记内。TouchableWithoutFeedback
以onPress作为道具,您可以在其中提供onPress事件。
有关TouchableWithoutFeedback
此链接
1> Manish..:
我用过TouchableWithoutFeedback
.为此,您需要将所有renderItem元素(即您的行)添加到TouchableWithoutFeedback
.然后添加onPress
事件并将FaltList项传递给onPress事件.
import {View, FlatList, Text, TouchableWithoutFeedback} from 'react-native';
render() {
return (
(
this.actionOnRow(item)}>
ID: {item.id}
Title: {item.title}
)}
/>
);
}
actionOnRow(item) {
console.log('Selected Item :',item);
}
2> Raj Suvariya..:
您需要将行元素(在renderItem方法内部)包装在
标记内。TouchableWithoutFeedback
以onPress作为道具,您可以在其中提供onPress事件。
有关TouchableWithoutFeedback
此链接