I want to display a custom dialog that have a listview inside it. First take a look on my code below.
Dialog:
protected void onPostExecute(String file_ur
Inflate your view and use the object returned by the inflater to look for the ListView
inside the layout
View view = inflater.inflate(R.layout.dialog_add, null)
ListView lv = (ListView) view.findViewById(R.id.lvAddDialog);
ListviewContactAdapter adapter = new ListviewContactAdapter(getActivity(), listContact);
lv.setAdapter(adapter);
builder.setView(view);
Change this:
ListviewContactAdapter adapter = new ListviewContactAdapter(getActivity(), listContact);
to this:
ListviewContactAdapter adapter = new ListviewContactAdapter(YourCLassName.this, listContact);
OR, may be you didn't initialize listContact
When you get the ListView yet not set te layout in the Dialog. You need build first your dialog and after get the ListView
Check this:
protected void onPostExecute(String file_url) {
btnInvite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
LayoutInflater inflater = getActivity().getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(inflater.inflate(R.layout.dialog_add, null))
.setTitle("Invite people")
.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
Dialog dialog = builder.create();
ListView lv = (ListView) dialog.findViewById(R.id.lvAddDialog);
ListviewContactAdapter adapter = new ListviewContactAdapter(getActivity(), listContact);
lv.setAdapter(adapter);
dialog.show();
}
});
}
}