android - ListView on click listener -


i have designed listfragment. on itemlongclick(), activity starts. onactivityresult(),i set adapter again , new text view being created dynamically. onclick of each views in item, toast shoud appear. if implement onclick() on each views in adapter itemlongclick() not working.

i have attached code below:

inside listfragment:

@override     public void onviewcreated(view view, bundle savedinstancestate) {         super.onviewcreated(view, savedinstancestate);         getlistview().setonitemlongclicklistener(new adapterview.onitemlongclicklistener() {              @override             public boolean onitemlongclick(adapterview<?> parent, view view,                     int position, long id) {                 clickposition = position;                 intent intent = new intent(parent.getcontext(),addeventactivity.class );                 startactivityforresult(intent, create_event);                 return true;             }         });     } 

inside adapter getview():

@override     public view getview(final int position, view convertview, final viewgroup parent) {         layoutinflater inflater = (layoutinflater)parent.getcontext().getsystemservice(context.layout_inflater_service);         view view = (view)inflater.inflate(r.layout.event_listview_items, null);         textview hour = (textview)view.findviewbyid(r.id.hour);         linearlayout layout = (linearlayout)view.findviewbyid(r.id.layout);           hour.settext(houral.get(position));         if(evental.size() != 0){             for(int i=0;i<evental.size();i++){                 if(evental.get(i).getposition() == position){                     for(int j =0;j<evental.get(i).eventname.size();j++){                         linearlayout.layoutparams params = new linearlayout.layoutparams(0,layoutparams.fill_parent,1.0f);                         params.setmargins(3, 3, 3, 3);                         final textview txt = new textview(parent.getcontext());                         txt.setid(++textid);                         txt.setbackgroundcolor(color.gray);                         txt.setlayoutparams(params);                         txt.settext(evental.get(i).eventname.get(j));                         layout.addview(txt);                          txt.setonclicklistener(new onclicklistener() {                             @override                             public void onclick(view v) {                                 toast.maketext(parent.getcontext(), txt.getid() + " clicked", toast.length_short).show();                              }                         });                     }                 }             }         }         return view;     } 

please guide me how implement both functions.

i have found out solution. dynamic views, have made setlongclickable() true.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -