如何在吐司上显示我想要的物品?

发布于 2024-12-06 05:39:27 字数 1396 浏览 1 评论 0原文

我第一次在安卓上做一个应用程序。我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞 2024-12-13 05:39:27

您需要在 ItemClickListener 上设置列表,如下所示:

private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v, int position, long id)
    {
        // Display a messagebox.
        Toast.makeText(this,"You clicked something!",Toast.LENGTH_SHORT).show();
    }
};

myList.setOnItemClickListener(mMessageClickedHandler);

当然,您必须将自己的数据(我猜是来自数据库或 Web 服务)输入到 Toast 消息中,以指示事件的日期、时间和位置。

编辑:根据您的评论,听起来您是 Android 开发的新手。您可能想查看这个很棒的教程来学习如何使用 SQLite ,以及一般的 Android SDK。

You would need to set your lists onItemClickListener like so:

private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v, int position, long id)
    {
        // Display a messagebox.
        Toast.makeText(this,"You clicked something!",Toast.LENGTH_SHORT).show();
    }
};

myList.setOnItemClickListener(mMessageClickedHandler);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文