我制作了一个应用程序,我可以在列表视图中查看我的所有应用程序,效果非常好。但是,我无法单击它,因为我还没有为其添加功能,如何将单击功能添加到列表视图?这是我的代码:
Java代码:
public class AllAppsActivity extends ListActivity {
LinearLayout appsLinearLayout;
ListView list;
Intent intent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.allapps_screen);
//Import views
appsLinearLayout = (LinearLayout)findViewById(R.id.appsLinearLayout);
//Set wallpaper
appsLinearLayout.setBackgroundResource(R.drawable.images);
//Load all apps
final PackageManager pm = this.getPackageManager();
intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ArrayList<ResolveInfo> list =
(ArrayList<ResolveInfo>) pm.queryIntentActivities(intent,
PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list)
{
Log.i("TAG", ": Installed Applications " + rInfo.activityInfo.
applicationInfo.loadLabel(pm).toString());
}
final ArrayAdapter<ResolveInfo> adapter =
new ArrayAdapter<ResolveInfo>(this, android.R.layout.simple_list_item_1, list)
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = super.getView(position, convertView, parent);
final String text = list.get(position).activityInfo.
applicationInfo.loadLabel(pm).toString();
((TextView)convertView).setText(text);
return convertView;
}
};
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
}
}