java - How to add list from cursor to intent in share button -
i have app use content provider work db. have list, inflated , shown user. need save list intent , send share button i found here
here questions-
1) need convert cursor list or need create second list , inflate cursor or there other variant? 2) how can customize of recieved message?
here code-
public class catalogactivity extends appcompatactivity implements loadermanager.loadercallbacks<cursor> { private static final string tag = "mylogs"; /** identifier pet data loader */ private static final int list_loader = 0; /** adapter listview */ listcursoradapter mcursoradapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_catalog); log.v(tag, "Зашли в catalog activity oncreate"); // setup fab open editoractivity floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intent intent = new intent(catalogactivity.this, editoractivity.class); startactivity(intent); } }); // find listview populated list data listview listlistview = (listview) findviewbyid(r.id.list); // find , set empty view on listview, shows when list has 0 items. view emptyview = findviewbyid(r.id.empty_view); listlistview.setemptyview(emptyview); // setup adapter create list item each row of list data in cursor. // there no items data yet (until loader finishes) pass in null cursor. mcursoradapter = new listcursoradapter(this, null); listlistview.setadapter(mcursoradapter); // setup item click listener listlistview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapterview, view view, int position, long id) { shoppinglistbdhelper helper = new shoppinglistbdhelper(view.getcontext()); if (helper.setcompleted(id)) { mcursoradapter.setcompleted(view); } } }); // kick off loader getsupportloadermanager().initloader(list_loader, null, this); } /** * helper method insert hardcoded item data database. debugging purposes only. */ private void insertpet() { log.v(tag, "Создали insertpet"); intent myintent = new intent(intent.action_send); string sharebody = "body here"; string sharesub = "sub here"; myintent.putextra(intent.extra_text, sharesub); myintent.putextra(intent.extra_text, sharebody); myintent.settype("text/plain"); startactivity(intent.createchooser(myintent, "share using")); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu options res/menu/menu_catalog.xml file. // adds menu items app bar. getmenuinflater().inflate(r.menu.menu_catalog, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // user clicked on menu option in app bar overflow menu switch (item.getitemid()) { // respond click on "insert dummy data" menu option case r.id.action_insert_dummy_data: insertpet(); return true; // respond click on "delete entries" menu option case r.id.action_delete_all_entries: deleteallitems(); return true; case r.id.menu_item_share: shareintent(); return true; } return super.onoptionsitemselected(item); } /** * helper method delete list in database. */ private void deleteallitems() { log.v(tag, "Сработал метод удаления всех данных"); long rowsdeleted = getcontentresolver().delete(listcontract.listentry.content_uri, null, null); log.v("catalogactivity", rowsdeleted + " rows deleted list database"); } private void shareintent(){ arraylist<string> list = new arraylist<string>(); intent sendintent = new intent(); sendintent.setaction(intent.action_send); sendintent.putstringarraylistextra("test", (arraylist<string>) list); sendintent.settype("text/plain"); startactivity(sendintent); } @override public loader<cursor> oncreateloader(int i, bundle bundle) { log.v(tag, "Начал работать loader cursor"); // define projection specifies columns table care about. string[] projection = { listcontract.listentry._id, listcontract.listentry.column_item_name, listcontract.listentry.column_item_description, listcontract.listentry.column_item_completed }; // loader execute contentprovider's query method on background thread return new cursorloader(this, // parent activity context listcontract.listentry.content_uri, // provider content uri query projection, // columns include in resulting cursor null, // no selection clause null, // no selection arguments null); // default sort order } @override public void onloadfinished(loader<cursor> loader, cursor data) { // update {@link listcursoradapter} new cursor containing updated pet data mcursoradapter.swapcursor(data); log.v(tag, "cursor adapter загрузился"); } @override public void onloaderreset(loader<cursor> loader) { // callback called when data needs deleted mcursoradapter.swapcursor(null); } }
you can use arraylist
instead stringbuilder
need convert arraylist
stringbuilder
, pass builder.tostring()
think working you.
Comments
Post a Comment