I am developing an app which is displaying some data to a ListView. The data is perfectly shown in the ListView (custom list view). i have used a custom adapter also which is extended by a BaseAdapter. i have modified my app to pop up a custom dialog box when some duplicated records are there in the list view. so my problem is the items in the custom dialog (in the list view ) does not respond to the onclick listener
here is my code (which is inside the adapter class)
public void showDuplicateDialog(ArrayList<HashMap<String, String>> list){
AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(activity);
LayoutInflater infl = activity.getLayoutInflater();
View view = infl.inflate(R.layout.dialog_list, null);
ListView lv = (ListView) view.findViewById(R.id.dialogList);
//NewsRowAdapter nw = new NewsRowAdapter(mContext, activity, R.layout.dialog_row, list);
SimpleAdapter sim = new SimpleAdapter(mContext, list, R.layout.dialog_row, new String[] { STIME,END, DATE }, new int[] {
R.id.stime2,R.id.etime2, R.id.blank2});
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "item clicked ", Toast.LENGTH_LONG).show();
}
});
/*ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.two_line_list_item, android.R.id.text1, Names);*/
alertDialogBuilder2.setView(view);
alertDialogBuilder2.setAdapter(sim, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "item clicked ", Toast.LENGTH_LONG).show();
}
})
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "Accepted", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
alertDialogBuilder2.show();
}
can someone tell me where the problem is ?
i have refer the developer instructions also.. they stated that below code should work.. but it is not responding at all.. no errors..no exceptions..but doesn't works
alertDialogBuilder2.setAdapter(sim, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "item clicked ", Toast.LENGTH_LONG).show();
}
})
please help me
If you are display custom layout including ListView then no need setAdapter on AlertDialog.
Just setAdapter on ListView Instead of AlertDialog.
________________________________
You can also use default functionality instead of custom view..
check this for more about alertdilaog.