Skip to content Skip to sidebar Skip to footer

Unable To Show Toast

How do I show roomId In Toast? In my code (MainActivity) below, I am unable to show a Toast: package com.android.listviewexample; import java.util.ArrayList; import java.util.HashM

Solution 1:

first of all add both items in list using following code:

list.add(model(name, roomid));

Also create a model class for RoomModel like this:

publicclassRoomModel {
    publicString name, id,  image, description;

    publicStringgetName() {
        return name;
    }

    publicvoidsetName(String name) {
        this.name = name;
    }

    publicStringgetId() {
        return id;
    }

    publicvoidsetId(String id) {
        this.id = id;
    }

}

and create a model in your activity class like this:

privateRoomModelmodel(String id, String name) {
        RoomModel m= newRoomModel();
        m.setId(id);
        m.setName(name);
        return m;
    }

Now in OnItemClickListener call:

Toast.makeText(getApplicationContext(),roomlist.get(position).getId());, Toast.LENGTH_LONG)
.show();

Post a Comment for "Unable To Show Toast"