1

I am making a Birthday Reminder App, in which i am allowing user to add birthdays for their friends those numbers are stored in Phone Book

Now i am trying to do small change, like here i want if User has already added birthday for Phonebook friend then no need to show AddBirthday button, and if user has not added birthday for Phonebook friend then need to show AddBirthday button.

like in my phone book, person name Akshat for him i have already added birthday, but here i am also getting AddBirthday button, but now i want to disable this AddBirthday Button

AccountDatesOfBirthAdapter.java:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (position == 0) {
        if (convertView == null) {
            convertView = this.inflater.inflate(R.layout.editor_account, null);
        }

        ImageView accountIcon = (ImageView) convertView.findViewById(R.id.editor_icon);
        accountIcon.setImageDrawable(this.accountIcon);

        TextView accountType = (TextView) convertView.findViewById(R.id.editor_type);
        accountType.setText(this.accountType);

        TextView accountName = (TextView) convertView.findViewById(R.id.editor_name);
        accountName.setText(this.accountName);

        // To Do:: Enable and Disable button (Birthday Added or not)
        addDateOfBirth = (ImageButton) convertView.findViewById(R.id.editor_new);
        addDateOfBirth.setOnClickListener(this);

        }
        else 
        {               
        DateOfBirth dateOfBirth = this.datesOfBirth.get(position - 1);

        if (convertView == null) {
            convertView = this.inflater.inflate(R.layout.editor_dateofbirth, null);
        }

        TextView date = (TextView) convertView.findViewById(R.id.editor_date);
        date.setText(dateFormatter.format(dateOfBirth.getDate().getTime()));
    }
    return convertView;
}
ASMUIRTI
  • 1,332
  • 10
  • 20
  • 1
    Where is the information about whether the birthday has already been added stored? – Egor Mar 20 '13 at 09:16

3 Answers3

1

Check in the database for dateofbirth of the person and if its there do

setClickable(false)

AND

setEnabled(false)

credits: https://stackoverflow.com/a/6750525/2071742

Edit: I think you want the button to be gone in which case you should use the addDateOfBirth.setVisibility(View.GONE); to remove it.

Community
  • 1
  • 1
smophos
  • 343
  • 2
  • 10
1

In Your AccountDatesOfBirthAdapter.java, you can put condition like

if(dateOfBirth != null){
   addDateOfBirth.setVisibility(View.GONE);
}else{
   addDateOfBirth.setVisibility(View.VISIBLE);
}
Kameswari
  • 738
  • 7
  • 27
1

Yes, i agree with @Kameswari, you just need to do a small change in your AccountsDateOfBirthAdapter.java:

   if(dateOfBirth != null){
       addDateOfBirth.setVisibility(View.GONE);
        }

Your code should look like this:

   TextView accountName = (TextView) convertView.findViewById(R.id.editor_name);
        accountName.setText(this.accountName);

        // To Do:: Enable and Disable button (Birthday Added or not)
        addDateOfBirth = (ImageButton) convertView.findViewById(R.id.editor_new);
        addDateOfBirth.setOnClickListener(this);

        }
        else 
        {               
        DateOfBirth dateOfBirth = this.datesOfBirth.get(position - 1);

        if (convertView == null) {
            convertView = this.inflater.inflate(R.layout.editor_dateofbirth, null);
        }

        TextView date = (TextView) convertView.findViewById(R.id.editor_date);
        date.setText(dateFormatter.format(dateOfBirth.getDate().getTime()));

        if(dateOfBirth != null){
               addDateOfBirth.setVisibility(View.GONE);
        }


    }
    return convertView;
}
Babu
  • 957
  • 1
  • 9
  • 21