如何在吐司上显示我想要的物品?
我第一次在安卓上做一个应用程序。我有 4 个字符串和一个 lisview。我想在用户按下 toast 上的列表视图上的项目时显示字符串。 任何人都可以帮我解决这个问题吗?
例如:我的列表视图中有事件 1、事件 2 和事件 3。 当用户按下事件 1 时,它将显示该事件的日期、时间、地点。
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Context context = getApplicationContext();
Toast.makeText(context,
"Date: "+date +" " +"Tme: "+ time, Toast.LENGTH_LONG).show();
Toast.makeText(context,"hi",Toast.LENGTH_LONG).show();
}
});
这是从 googleCalendar 中提取它的代码
date = contentResult[0].substring(10, 21);
time = contentResult[0].substring(21, 36);
location = contentResult[2].substring(6);
description = contentResult[4].substring(18);
eventTitle[i] = name;
eventDate[i] = date;
eventTime[i] = time;
eventVenue[i] = location;
eventContent[i] = description;
event[i] = name + " " + "Date: " +date + " " + "Time: " +time + " " +" Location:"+ location+ "Event Description:"+ description ;
my first time doing an app on android. i have 4 strings and a lisview.i want to display the strings whenever user press the items on the listview on a toast.
can any one help me on this ?
For eg: there are Event 1 ,event 2 and event 3 on my list view.
and when user press event 1. it will display the date, time , venue for that event.
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Context context = getApplicationContext();
Toast.makeText(context,
"Date: "+date +" " +"Tme: "+ time, Toast.LENGTH_LONG).show();
Toast.makeText(context,"hi",Toast.LENGTH_LONG).show();
}
});
This is the codes for extracting it out from googleCalendar
date = contentResult[0].substring(10, 21);
time = contentResult[0].substring(21, 36);
location = contentResult[2].substring(6);
description = contentResult[4].substring(18);
eventTitle[i] = name;
eventDate[i] = date;
eventTime[i] = time;
eventVenue[i] = location;
eventContent[i] = description;
event[i] = name + " " + "Date: " +date + " " + "Time: " +time + " " +" Location:"+ location+ "Event Description:"+ description ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 ItemClickListener 上设置列表,如下所示:
当然,您必须将自己的数据(我猜是来自数据库或 Web 服务)输入到 Toast 消息中,以指示事件的日期、时间和位置。
编辑:根据您的评论,听起来您是 Android 开发的新手。您可能想查看这个很棒的教程来学习如何使用 SQLite ,以及一般的 Android SDK。
You would need to set your lists onItemClickListener like so:
Of course you would have to input your own data (I'm guessing from a database or web service) to the Toast message indicating the date, time, and location of the event.
EDIT: In response to your comment, it sounds like you are new to Android development. You might want to check out this great tutorial to learn how to use SQLite, and the Android SDK in general.