Guest User

Untitled

a guest
Mar 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. <RelativeLayout>
  2. <ImageView/>
  3. <TextView/>
  4. <TextView/>
  5. </RelativeLayout>
  6.  
  7. <LinearLayout>
  8. <ListView/>
  9. <Button/>
  10. </LinearLayout>
  11.  
  12. public class LancherApp extends Activity {
  13.  
  14. //
  15. private ArrayList<String> items = null;
  16. //
  17. private ApplicationListAdapter adapter = null;
  18.  
  19. @Override
  20. protected void onCreate (Bundle bundle) {
  21. super.onCreate (bundle);
  22. requestWindowFeature (Window.FEATURE_NO_TITLE);
  23.  
  24. setContentView (R.layout.activity_main);
  25. // create String Arraylist.
  26. List<AppData> appList = new ArrayList<AppData>();
  27. // create PackageManager.
  28. PackageManager packageManager = getPackageManager();
  29. // make application list in your device has already installed.
  30. final List<ApplicationInfo> installedAppList = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
  31.  
  32. for (ApplicationInfo app : installedAppList) {
  33. AppData data = new AppData();
  34. data.label = app.loadLabel(packageManager).toString();
  35. data.icon = app.loadIcon(packageManager);
  36. data.name = app.packageName;
  37. appList.add (data);
  38. }
  39.  
  40. final ListView listView = (ListView) findViewById(R.id.list);
  41. adapter = new ApplicationListAdapter(this, appList);
  42. listView.setAdapter(adapter);
  43. }
  44.  
  45. // private Adapter Class indicates label and icon of application.
  46. private static class ApplicationListAdapter extends ArrayAdapter<AppData> {
  47. //
  48. private final LayoutInflater mInflater;
  49.  
  50. public ApplicationListAdapter (Context context, List<AppData> dataList) {
  51. super(context, R.layout.list_item);
  52. mInflater = (LayoutInflater)
  53. context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
  54. addAll(dataList);
  55. }
  56.  
  57. @Override
  58. public View getView (int position, View convertView, ViewGroup parent) {
  59. ViewHolder holder = new ViewHolder();
  60.  
  61. if (convertView == null) {
  62. convertView = mInflater.inflate(R.layout.list_item, parent, false);
  63. holder.textLabel = (TextView) convertView.findViewById(R.id.label);
  64. holder.imageIcon = (ImageView) convertView.findViewById(R.id.icon);
  65. holder.packageName = (TextView) convertView.findViewById(R.id.name);
  66. convertView.setTag(holder);
  67. } else {
  68. holder = (ViewHolder) convertView.getTag();
  69. }
  70.  
  71. //
  72. final AppData data = getItem(position);
  73. //
  74. holder.textLabel.setText(data.label);
  75. holder.imageIcon.setImageDrawable(data.icon);
  76. holder.packageName.setText(data.name);
  77.  
  78. return convertView;
  79. }
  80. }
  81.  
  82. // private class for storing application data.
  83. private static class AppData {
  84. String label;
  85. Drawable icon;
  86. String name;
  87. }
  88.  
  89. // private class ViewHolder.
  90. private static class ViewHolder {
  91. TextView textLabel;
  92. ImageView imageIcon;
  93. TextView packageName;
  94. }
  95. }
  96.  
  97. <?xml version="1.0" encoding="utf-8"?>
  98. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  99. android:layout_width="match_parent"
  100. android:layout_height="match_parent"
  101. android:orientation="vertical">
  102.  
  103. <ListView
  104. android:id="@+id/list"
  105. android:layout_width="match_parent"
  106. android:layout_height="0"
  107. android:layout_weight="1"/>
  108.  
  109. <Button
  110. android:id="@+id/button4"
  111. android:layout_width="match_parent"
  112. android:layout_height="wrap_content"
  113. android:text="Button" />
  114.  
  115. </LinearLayout>
  116.  
  117. <?xml version="1.0" encoding="utf-8"?>
  118. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  119. android:layout_width="match_parent"
  120. android:layout_height="match_parent"
  121. android:orientation="vertical">
  122.  
  123. <ImageView
  124. android:id="@+id/icon"
  125. android:layout_width="50dp"
  126. android:layout_height="50dp"
  127. android:layout_alignParentLeft="true"
  128. android:layout_alignParentTop="true"
  129. android:layout_weight="1"/>
  130.  
  131. <TextView
  132. android:id="@+id/label"
  133. android:layout_width="wrap_content"
  134. android:layout_height="wrap_content"
  135. android:layout_alignParentRight="true"
  136. android:layout_alignParentTop="true"
  137. android:layout_toRightOf="@+id/icon"
  138. android:textSize="18sp"
  139. android:layout_weight="1"/>
  140.  
  141. <TextView
  142. android:id="@+id/name"
  143. android:layout_width="wrap_content"
  144. android:layout_height="wrap_content"
  145. android:layout_alignLeft="@+id/label"
  146. android:layout_alignParentRight="true"
  147. android:layout_below="@+id/label"
  148. android:layout_weight="1" />
  149.  
  150. </RelativeLayout>
Add Comment
Please, Sign In to add comment