본문 바로가기
프로그래밍/Android

Android Popup Dialog(팝업 다이얼로그)

by CaffeLatte 2015. 5. 18.

클래스 내부에서 함수로 팝업 다이얼로그를 구현


/**
* 검색 카테고리 팝업 설정
*/
private void setPopupSearchCategory() {
setSearchCategoryList();

LayoutInflater inflater = getLayoutInflater();
View convertView = inflater.inflate(R.layout.popup_search_category, null);

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(convertView);

TextView tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
Button btnClose = (Button) convertView.findViewById(R.id.btn_popup_close);
ListView listView = (ListView) convertView.findViewById(R.id.lv_search_key_all);

int keyIndex = searchKeySpnAdapter.selectedPosition;
String title = getResources().getString(R.string.select) + " " + searchKeyList.get(keyIndex);
tvTitle.setText(title);
listView.setAdapter(new SearchPopupAdapter(context, searchCategoryList));

final AlertDialog dialog = builder.create();
dialog.show();

btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String category = searchCategoryList.get(position);
etSearch.setText(category);
ToastUtil.showShortToast(context, category, true);
dialog.dismiss();
}

});
}


댓글