Android 获取Launcher 启动列表
2010-08-22 04:28:00 来源:WEB开发网tv.setPadding(10, 5, 0, 0);
layout.addView(tv);
return layout;
}
}
public class LauncherAdapter extends BaseAdapter {
Activity activity;
public LauncherAdapter(Activity a){
activity = a;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return lvalue.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return composeItem(position);
}
public View composeItem(int position){
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.HORIZONTAL);
ImageView iv = new ImageView(activity);
iv.setImageDrawable(lvalue.get(position).icon);
layout.addView(iv);
TextView tv = new TextView(activity);
tv.setText(lvalue.get(position).name);
tv.setPadding(10, 5, 0, 0);
layout.addView(tv);
return layout;
}
}
4. 启动某个item 当单击时
Java代码
adapter = new LauncherAdapter(this);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Intent intent =new Intent(Intent.ACTION_VIEW);
intent.setComponent(lvalue.get(arg2).component);
更多精彩
赞助商链接