Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <RelativeLayout>
- <ImageView/>
- <TextView/>
- <TextView/>
- </RelativeLayout>
- <LinearLayout>
- <ListView/>
- <Button/>
- </LinearLayout>
- public class LancherApp extends Activity {
- //
- private ArrayList<String> items = null;
- //
- private ApplicationListAdapter adapter = null;
- @Override
- protected void onCreate (Bundle bundle) {
- super.onCreate (bundle);
- requestWindowFeature (Window.FEATURE_NO_TITLE);
- setContentView (R.layout.activity_main);
- // create String Arraylist.
- List<AppData> appList = new ArrayList<AppData>();
- // create PackageManager.
- PackageManager packageManager = getPackageManager();
- // make application list in your device has already installed.
- final List<ApplicationInfo> installedAppList = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
- for (ApplicationInfo app : installedAppList) {
- AppData data = new AppData();
- data.label = app.loadLabel(packageManager).toString();
- data.icon = app.loadIcon(packageManager);
- data.name = app.packageName;
- appList.add (data);
- }
- final ListView listView = (ListView) findViewById(R.id.list);
- adapter = new ApplicationListAdapter(this, appList);
- listView.setAdapter(adapter);
- }
- // private Adapter Class indicates label and icon of application.
- private static class ApplicationListAdapter extends ArrayAdapter<AppData> {
- //
- private final LayoutInflater mInflater;
- public ApplicationListAdapter (Context context, List<AppData> dataList) {
- super(context, R.layout.list_item);
- mInflater = (LayoutInflater)
- context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
- addAll(dataList);
- }
- @Override
- public View getView (int position, View convertView, ViewGroup parent) {
- ViewHolder holder = new ViewHolder();
- if (convertView == null) {
- convertView = mInflater.inflate(R.layout.list_item, parent, false);
- holder.textLabel = (TextView) convertView.findViewById(R.id.label);
- holder.imageIcon = (ImageView) convertView.findViewById(R.id.icon);
- holder.packageName = (TextView) convertView.findViewById(R.id.name);
- convertView.setTag(holder);
- } else {
- holder = (ViewHolder) convertView.getTag();
- }
- //
- final AppData data = getItem(position);
- //
- holder.textLabel.setText(data.label);
- holder.imageIcon.setImageDrawable(data.icon);
- holder.packageName.setText(data.name);
- return convertView;
- }
- }
- // private class for storing application data.
- private static class AppData {
- String label;
- Drawable icon;
- String name;
- }
- // private class ViewHolder.
- private static class ViewHolder {
- TextView textLabel;
- ImageView imageIcon;
- TextView packageName;
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <ListView
- android:id="@+id/list"
- android:layout_width="match_parent"
- android:layout_height="0"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/button4"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Button" />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <ImageView
- android:id="@+id/icon"
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_weight="1"/>
- <TextView
- android:id="@+id/label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:layout_toRightOf="@+id/icon"
- android:textSize="18sp"
- android:layout_weight="1"/>
- <TextView
- android:id="@+id/name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/label"
- android:layout_alignParentRight="true"
- android:layout_below="@+id/label"
- android:layout_weight="1" />
- </RelativeLayout>
Add Comment
Please, Sign In to add comment