Good for starters, use the function for the part that you explicitly copied and pasted.
if (Avatar==1) setImage(R.drawable.avatar1);
if (Avatar==2) setImage(R.drawable.avatar2);
if (Avatar==3) setImage(R.drawable.avatar3);
private void setImage(final int resource)
{
((ImageView)(dialogPopup.findViewById(R.id.imgView))).setImageResource(resource);
}
This, at least, cuts it horizontally and removes a lot of duplication.
, :
private int getResource(final int avatar)
{
switch(avatar)
{
case 1: return R.drawable.avatar1;
case 2: return R.drawable.avatar2;
case 3: return R.drawable.avatar3;
default:
throw new RuntimeException("No avatar for this");
}
}
:
setImage(getResource(avatar));