java - How to get multiple Item selector ListView in android -
i developing app in want list of installed apps on device , show in list view of app. succeed in doing so. below code this.but there problem want user selected multiple items in shown listview of installed apps.i dont know how convert simple listview multiple item selector listview. every kind of appreciated.
main_activity.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.pc.fkidshell.teen3activity"> <include layout="@layout/toolbar" android:id="@+id/my_teen3toolbar"/> <listview android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/list"></listview> </linearlayout>
list_item.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <imageview android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/app_icon" android:padding="3dp" android:scaletype="centercrop" android:contentdescription="@null"/> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingleft="5dp" android:gravity="center_vertical"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/app_name" android:gravity="center_vertical" android:textstyle="bold"/> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/app_package" android:gravity="center_vertical" android:textstyle="bold"/> </linearlayout> </linearlayout>
appadapter.java
public class appadapter extends arrayadapter<applicationinfo> { private list<applicationinfo> applist=null; private context context; private packagemanager packagemanager; public appadapter(context context, int resource, list<applicationinfo> objects) { super(context, resource, objects); this.context=context; this.applist=objects; packagemanager=context.getpackagemanager(); } @override public int getcount() { return ((null!=applist)?applist.size():0); } @override public applicationinfo getitem(int position) { return ((null!=applist)?applist.get(position):null); } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { view view = convertview; if (null == view) { layoutinflater layoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view = layoutinflater.inflate(r.layout.list_item, null); } applicationinfo data = applist.get(position); if (null != data) { textview appname = (textview) view.findviewbyid(r.id.app_name); textview packagename = (textview) view.findviewbyid(r.id.app_package); imageview iconview = (imageview) view.findviewbyid(r.id.app_icon); appname.settext(data.loadlabel(packagemanager)); packagename.settext(data.packagename); iconview.setimagedrawable(data.loadicon(packagemanager)); } return view; } }
mainactivity.java:
public class teen3activity extends listactivity { toolbar teen3tb; private packagemanager packagemanager = null; private list<applicationinfo> applist = null; private appadapter listadaptor = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_teen3); teen3tb=(toolbar) findviewbyid(r.id.my_teen3toolbar); //setsupportactionbar(teen3tb); //getsupportactionbar().settitle("list of apps"); packagemanager = getpackagemanager(); new loadapplications().execute(); } private list<applicationinfo> checkforlaunchintent(list<applicationinfo> list) { arraylist<applicationinfo> applist = new arraylist<applicationinfo>(); (applicationinfo info : list) { try { if (null != packagemanager.getlaunchintentforpackage(info.packagename)) { applist.add(info); } } catch (exception e) { e.printstacktrace(); } } return applist; } private class loadapplications extends asynctask<void, void, void> { private progressdialog progress = null; @override protected void doinbackground(void... params) { applist = checkforlaunchintent(packagemanager.getinstalledapplications(packagemanager.get_meta_data)); listadaptor = new appadapter(teen3activity.this, r.layout.list_item, applist); return null; } @override protected void oncancelled() { super.oncancelled(); } @override protected void onpostexecute(void result) { setlistadapter(listadaptor); progress.dismiss(); super.onpostexecute(result); } @override protected void onpreexecute() { progress = progressdialog.show(teen3activity.this, null, "loading application info..."); super.onpreexecute(); } @override protected void onprogressupdate(void... values) { super.onprogressupdate(values); } } }
Comments
Post a Comment