import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends Activity {
private List<ApplicationInfo> appList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Button btn = (Button) findViewById(R.id.btn);
PackageManager pm = getPackageManager();
appList = pm.getInstalledApplications(0);
Iadapter adapter = new Iadapter(this, R.layout.custom_list_view, appList, pm);
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setOnItemClickListener(onItemClickListener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id)
{
Intent intent;
String appPkgName = appList.get(pos).packageName;
intent = getPackageManager().getLaunchIntentForPackage(appPkgName);
if(intent == null) {
Toast.makeText(getApplication(), "실행할 수 없는 어플리케이션입니다.", Toast.LENGTH_SHORT).show();
return;
}
startActivity(intent);
}
};
}
import android.graphics.drawable.Drawable;
public class IconInfo {
private Drawable icon;
private String appName;
private String appPkg;
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public String getAppPkg() {
return appPkg;
}
public void setAppPkg(String appPkg) {
this.appPkg = appPkg;
}
}
import java.util.List;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class Iadapter extends BaseAdapter{
@SuppressWarnings("unused")
private Context context;
private LayoutInflater inflater;
private List<ApplicationInfo> appList;
private int layout;
private PackageManager pm;
public Iadapter(Context context, int layout, List<ApplicationInfo> appList, PackageManager pm)
{
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.appList = appList;
this.layout = layout;
this.pm = pm;
}
@Override
public int getCount() {
return appList.size();
}
@Override
public Object getItem(int pos) {
return appList.get(pos);
}
@Override
public long getItemId(int pos) {
return pos;
}
@Override
public View getView(int pos, View view, ViewGroup viewGrp) {
if(view == null) {
view = inflater.inflate(layout, viewGrp, false);
}
// List<ApplicationInfo> appList = pm.getInstalledApplications(0);
TextView tvAppName = (TextView) view.findViewById(R.id.appName);
TextView tvAppPkg = (TextView) view.findViewById(R.id.appPkg);
ImageView imgView = (ImageView) view.findViewById(R.id.imgView);
imgView.setImageDrawable(appList.get(pos).loadIcon(pm));
tvAppName.setText(appList.get(pos).loadLabel(pm));
tvAppPkg.setText(appList.get(pos).packageName);
return view;
}
}
저랑 제 친구랑 어플제작을 하는데 저도 어느정도 하는줄 알았더니 친구가 보내준 소스(위 글 내용)을 보니 까막눈이 되버리네요;; 간단하게나마 주석을 써주실수 있으신분 좀 도와주세요ㅠㅠㅠㅠ