android - Put a string into a dialog from a slected list item from a expandable list child -


i've been trying pull details of item selected, strings.xml. dialog pop when select item expandable list view (child). sadly little success.

this expandable list fragment navigationdrawerfragment. works great. dialog pulls template text.

case 2:      rootview = inflater.inflate(r.layout.fragment_item_list, container, false);        // listview      explistview = (expandablelistview) rootview.findviewbyid(r.id.lvexp);      // preparing list data      preparelistdata();      listadapter = new expandablelistadapter(this, listdataheader, listdatachild);      // setting list adapter      explistview.setadapter(listadapter);        // listview on child click listener      explistview.setonchildclicklistener(new expandablelistview.onchildclicklistener() {          @override          public boolean onchildclick(expandablelistview parent, view v,                                      int groupposition, int childposition, long id) {                // custom dialog              final dialog dialog = new dialog(getactivity());              dialog.setcontentview(r.layout.custom);              dialog.settitle("spell details");                // set custom dialog components - text, image , button                 textview text = (textview) dialog.findviewbyid(r.id.text);                 string content = istdatachild.get(childposition).tostring();                 text.settext(content);  //          imageview image = (imageview) dialog.findviewbyid(r.id.image);  //          image.setimageresource(r.drawable.ic_launcher);                button dialogbutton = (button) dialog.findviewbyid(r.id.dialogbuttonok);              // if button clicked, close custom dialog              dialogbutton.setonclicklistener(new view.onclicklistener() {                  @override                  public void onclick(view v) {                      dialog.dismiss();                  }              });                dialog.show();              return false;          }      });      break;

my list expandable list view

        private void preparelistdata() {              listdataheader = new arraylist<>();              listdatachild = new hashmap<>();                // adding child data              listdataheader.add("air");                // adding child data              list<string> air = new arraylist<string>();              air.add("air jet\n"+"ref. magic 24");                listdatachild.put(listdataheader.get(0), air); // header, child data    }

and adapter:

import java.util.hashmap;  import java.util.list;  import android.content.context;  import android.graphics.typeface;  import android.view.layoutinflater;  import android.view.view;  import android.view.viewgroup;  import android.widget.baseexpandablelistadapter;  import android.widget.textview;    public class expandablelistadapter extends baseexpandablelistadapter {        private mainactivity.placeholderfragment _context;      private list<string> _listdataheader; // header titles      // child data in format of header title, child title      private hashmap<string, list<string>> _listdatachild;        public expandablelistadapter(mainactivity.placeholderfragment context, list<string> listdataheader,                                   hashmap<string, list<string>> listchilddata) {          this._context = context;          this._listdataheader = listdataheader;          this._listdatachild = listchilddata;      }        @override      public object getchild(int groupposition, int childposititon) {          return this._listdatachild.get(this._listdataheader.get(groupposition))                  .get(childposititon);      }        @override      public long getchildid(int groupposition, int childposition) {          return childposition;      }        @override      public view getchildview(int groupposition, final int childposition,                               boolean islastchild, view convertview, viewgroup parent) {            final string childtext = (string) getchild(groupposition, childposition);            if (convertview == null) {              layoutinflater infalinflater = (layoutinflater) this._context.getactivity().getsystemservice(context.layout_inflater_service);              convertview = infalinflater.inflate(r.layout.list_item, null);          }            textview txtlistchild = (textview) convertview                  .findviewbyid(r.id.lbllistitem);            txtlistchild.settext(childtext);          return convertview;        }        @override      public int getchildrencount(int groupposition) {          return this._listdatachild.get(this._listdataheader.get(groupposition))                  .size();      }        @override      public object getgroup(int groupposition) {          return this._listdataheader.get(groupposition);      }        @override      public int getgroupcount() {          return this._listdataheader.size();      }        @override      public long getgroupid(int groupposition) {          return groupposition;      }        @override      public view getgroupview(int groupposition, boolean isexpanded,                               view convertview, viewgroup parent) {          string headertitle = (string) getgroup(groupposition);            if (convertview == null) {              layoutinflater infalinflater = (layoutinflater) this._context                      .getactivity().getsystemservice(context.layout_inflater_service);              convertview = infalinflater.inflate(r.layout.list_group, null);          }            textview lbllistheader = (textview) convertview                  .findviewbyid(r.id.lbllistheader);          lbllistheader.settypeface(null, typeface.bold);          lbllistheader.settext(headertitle);          return convertview;      }        @override      public boolean hasstableids() {          return false;      }        @override      public boolean ischildselectable(int groupposition, int childposition) {          return true;      }  }

eureka have figured out!

textview text = (textview) dialog.findviewbyid(r.id.text);  string str = (string) parent.getitematposition(childposition +1);  text.settext(str);


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -