button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(PersonalizeSettingsActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.custom, null);
alertDialog.setView(convertView);
alertDialog.setTitle("Branches");
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
ListViewAdapterBranch adapter = new ListViewAdapterBranch(branchList, getApplicationContext());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Branch branch = branchList.get(position);
button2.setText("Branch: "+branch.getName());
}
});
alertDialog.show();
}
});
here branch list contain the list of item. now i want to hide or close this custom dialog box when i click on the list item
put a global variable for
AlertDialog alert;
and when creating the dialogBuilder put
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(PersonalizeSettingsActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.custom, null);
alertDialog.setView(convertView);
alertDialog.setTitle("Branches");
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
ListViewAdapterBranch adapter = new ListViewAdapterBranch(branchList, getApplicationContext());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Branch branch = branchList.get(position);
button2.setText("Branch: "+branch.getName());
alert.dismiss();
}
});
alert = alertDialog.create();
alert .show();
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.