创建多个TouchableOpacity的时候,如何区分点击哪一个TouchableOpacity
2018-02-24 16:44
344 查看
循环创建多个view:
<View style = {styles.view_promotion}>
<View style = {styles.view_promotion_title}>
{this.state.title.map((key, i) => this.renderTitle(i, key))}
</View>
</View>
renderTitle(index, title) {
return(
<TouchableOpacity
style = {[styles.view_btn_title, {borderLeftWidth: 0}]}
key = {title}
onPress = {() => {this.onPressBrandButton(index)}}
underlayColor = 'red'
>
<Text style = {[styles.text_title,{color: 'yellow'}]}>
{title}
</Text>
</TouchableOpacity>
)
}
onPressBrandButton(i) {
Alert.alert('序号:' + i.toString())
}
参考:http://bbs.reactnative.cn/topic/2562/for%E5%BE%AA%E7%8E%AF%E5%88%9B%E5%BB%BAtouchableopacity%E5%AF%B9%E8%B1%A1%E6%97%B6-%E7%82%B9%E5%87%BB%E6%97%B6%E6%80%8E%E4%B9%88%E5%88%A4%E6%96%AD%E5%85%B7%E4%BD%93%E7%82%B9%E5%87%BB%E4%BA%86%E5%93%AA%E4%B8%80%E4%B8%AA/4
<View style = {styles.view_promotion}>
<View style = {styles.view_promotion_title}>
{this.state.title.map((key, i) => this.renderTitle(i, key))}
</View>
</View>
renderTitle(index, title) {
return(
<TouchableOpacity
style = {[styles.view_btn_title, {borderLeftWidth: 0}]}
key = {title}
onPress = {() => {this.onPressBrandButton(index)}}
underlayColor = 'red'
>
<Text style = {[styles.text_title,{color: 'yellow'}]}>
{title}
</Text>
</TouchableOpacity>
)
}
onPressBrandButton(i) {
Alert.alert('序号:' + i.toString())
}
参考:http://bbs.reactnative.cn/topic/2562/for%E5%BE%AA%E7%8E%AF%E5%88%9B%E5%BB%BAtouchableopacity%E5%AF%B9%E8%B1%A1%E6%97%B6-%E7%82%B9%E5%87%BB%E6%97%B6%E6%80%8E%E4%B9%88%E5%88%A4%E6%96%AD%E5%85%B7%E4%BD%93%E7%82%B9%E5%87%BB%E4%BA%86%E5%93%AA%E4%B8%80%E4%B8%AA/4
相关文章推荐
- 如何区分多个百度地图marker的点击事件
- Matlab如何创建多个Legend(图例)
- Android模拟内存紧张,应用被杀死如何模拟应用程序被杀掉? 更新:Daniel Lew指出,最简单的方法是在DDMS中点击”Stop Porcess”杀掉你的程序,在你调试程序的时候可以这样做。
- 自定义View 来创建一个圆 并且 在圆中心 每当点击的时候数字自增一
- vue中如何创建多个ueditor实例教程
- 如何在一个工作站里创建多个工程(同一个xcode下面创建多个工程)
- 如果创建工程的时候没有勾选Unit Test选项,如何创建单元测试 正确删除test target
- Android 如何创建子线程以及区分主线程
- UITableView中关于cell里的按钮被点击时如何确定是哪一个cell
- websocket:如何建立在同一台client和同一台server创建多个连接
- 如何创建多个Memcached服务
- UIAlertView点击确定后,如何跳转到storyboard中创建的另一个UIViewController?
- 如何在点击提交按钮时候执行以下语句
- H5页面,部分 Android手机点击number电话号码/成串数字时候,会跳转到其他页面造成404错误,如何解决?
- 【iOS开发-37】在点击或者输入结束后不需要键盘的时候如何隐藏并退出软键盘?
- eclipse下开发Android创建xml文件的时候,xml文件背景默认是黑色,如何解决?
- 如何在命令行创建mysql数据库的时候指定某种固定的编码方式
- 如何取消或定制当点击GridView 的时候出现的那个黄色背景
- react native TouchableOpacity(点击渐变) TextInput
- 如何在点击android中的EditText的时候不弹出软键盘