android - 如何获取 TextWidget onTap 的文本
问题描述
我有一个在文本小部件中显示日期的 ListView。在点击文本小部件时,我想要字符串中的文本。我怎么能得到那个?
这是我的代码。
children: <Widget>[
GestureDetector(
onTap: () {
print('OnTapped');
print(arrayDay[i].toString());
// get the text of TextWidget here
},
child: new Text(
arrayDay[i].toString(),
style: new TextStyle(
fontWeight: FontWeight.w400),
),
),
解决方案
在点击方法中,您可以从列表中获取数据。所以我在这里发布了一些代码,所以得到更多的想法
return ListView.builder(
itemCount: count,
itemBuilder: (BuildContext context, int position) {
return Card(
color: Colors.white,
elevation: 2.0,
child: ListTile(
title: Text(this.noteList[position].title,
style: titleStyle,
),
subtitle: Text(this.noteList[position].date),
onTap: () {
debugPrint('Note Data '+ this.noteList[position].title);
debugPrint('Data '+ 'Here your Data Get'); // you can get data here
},
),
); // Card
});
推荐阅读
- python - 如何在 Python OpenCV 或 skimage 中实现 MATLAB 的 edge() 函数
- c# - 使用实体框架从数据库中选择数据的通用函数
- scala - 对于理解 scala
- xamarin.forms - 在 Xamarin.Forms 中具有水平方向的分组 CollectionView?
- c# - 问题是事件仅添加了具有客户端 ID 和客户端密钥的单个用户尊重
- postman - MS Graph API - 获取需要多因素身份验证的访问令牌
- python - 用户登录 django 时用户身份验证失败
- pointers - 如何创建自引用结构?
- api - 使用 API 跟踪 edX 或 Udemy 课程进度
- svg - 与 Blink 和 Gecko 相比,为什么 Webkit/Safari(iOS、macOS)以不同的顺序呈现我的 SVG 转换?