I require a listview in a dialog with each row having the name of the app, icon and checkbox. I have used an adapter class that generates each row. I have done as :
lv = (ListView) findViewById(R.id.aplist);
lv.setAdapter(applistadapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
/* some code*/
} });
public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
private List<ApplicationInfo> appsList = null;
private Context context;
private PackageManager packageManager;
private TextView appName;
private ImageView iconview;
CheckBox check;
boolean[] itemChecked;
public ApplicationAdapter(Context context, int textViewResourceId,
List<ApplicationInfo> appsList) {
super(context, textViewResourceId, appsList);
this.context = context;
this.appsList = appsList;
packageManager = context.getPackageManager();
itemChecked = new boolean[appsList.size()];
Log.wtf("c", "34werty");
}
@Override
public int getCount() {
return ((null != appsList) ? appsList.size() : 0);
}
@Override
public boolean isEnabled(int position) {
return true;
}
@Override
public ApplicationInfo getItem(int position) {
Log.wtf("c", "23werty");
return ((null != appsList) ? appsList.get(position) : null);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (null == view) {
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.row, null);
Log.wtf("c", "12werty");
}
ApplicationInfo data = appsList.get(position);
if (null != data) {
Log.wtf("c", "werty");
appName = (TextView) view.findViewById(R.id.app_name);
// TextView packageName = (TextView)
// view.findViewById(R.id.app_paackage);
iconview = (ImageView) view.findViewById(R.id.app_icon);
check = (CheckBox) view.findViewById(R.id.checkbox1);
appName.setText(data.loadLabel(packageManager));
// packageName.setText(data.packageName);
iconview.setImageDrawable(data.loadIcon(packageManager));
check.setChecked(false);
if (itemChecked[position])
check.setChecked(true);
else
check.setChecked(false);
check.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (check.isChecked())
itemChecked[position] = true;
else
itemChecked[position] = false;
check.setTag(position);
}
});
}
return view;
}
};
Now the problem is that the control never goes to setOnItemClickListener().
Please help me to solve it.
Thank you.