android - How to see text in toast -


i'm trying see text gridview using toast when selected or clicked on gridview's data. can see position, don't know put see text. here code.

import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.gridview; import android.widget.toast;  public class mainactivity extends activity {     string [] data = {"a","b", "c","d","e","f", "g","h"};     gridview gdview;     arrayadapter<string> adapter;     string result;          @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          adapter = new arrayadapter<string>(this, r.layout.item, r.id.tvtext, data);          gdview = (gridview) findviewbyid(r.id.gdview);         gdview.setadapter(adapter);           gdview.setonitemclicklistener(new adapterview.onitemclicklistener()         {             public void onitemclick(adapterview<?> parent, view v,                                     int position, long id) {              toast.maketext(getbasecontext(), position, toast.length_short).show();             }         });     } } 

could suggest me, need use or it? thank you

the parameter int position of method onitemclick() on adapterview.onitemclicklistener gives you:

the position of view in adapter.

see here: https://developer.android.com/reference/android/widget/adapterview.onitemclicklistener.html#onitemclick(android.widget.adapterview, android.view.view, int, long)

you can use retrieve content of view arrayadapter with:

adapter.getitem(position) 

see here: https://developer.android.com/reference/android/widget/arrayadapter.html#getitem(int)

this return content of arrayadapter @ given position, in case string, can store in variable if or pass directly toast.maketext().


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -