开发者

how to display items i want on a toast?

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,
         开发者_JAVA技巧       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 ;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜