Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ShinJJang/1697109e672562ae0277 to your computer and use it in GitHub Desktop.
Save ShinJJang/1697109e672562ae0277 to your computer and use it in GitHub Desktop.
Android Delete button Visibility
/**
* Parameter의 state(View.VISIBLE, INVISIBLE)에 따라
* 연락처의 각 view에 삭제 버튼의 Visibility를 설정
* @param state 설정할 Visibility(View.VISIBLE, INVISIBLE)
*/
private void switchDeleteItemButtonVisibility(int state) {
ArrayList<Contact> frequentContacts = getFrequntlyContacts();
for (int i = 0; i <= contact_table.getChildCount() - 1; i++) {
TableRow row = (TableRow) contact_table.getChildAt(i);
for (int j = 0; j < 2; j++) {
View item = row.getChildAt(j);
if (item != null) {
ImageButton deleteButton = (ImageButton) item.findViewById(R.id.contact_item_delete);
Contact deleteContact = (Contact) deleteButton.getTag();
Boolean isFrequnt = false;
for (Contact contact : frequentContacts)
if (contact.id.equals(deleteContact.id))
isFrequnt = true;
if (!isFrequnt)
deleteButton.setVisibility(state);
}
}
}
// 하단의 삭제 버튼을 삭제 완료 버튼으로 변경과 본래 삭제 버튼으로 돌아옴
if (state == View.INVISIBLE) {
delete_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.delete, 0, 0, 0);
delete_button.setText(context.getResources().getString(R.string.delete));
} else {
delete_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.done, 0, 0, 0);
delete_button.setText(context.getResources().getString(R.string.done));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment