I'm trying to change src of ImageView from inside non-activity class and display Error dialog message at the same time, the dialog message is appeared but without any changes on the src of ImageView this is my code by using inflater, I don't know what is the problem.
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View view = inflater.inflate( R.layout.control_fragment, null );
ImageView imgView = (ImageView)view.findViewById(R.id.okimg);
imgView.setImageResource(R.drawable.clear);
Updated: Complete class
public class AddressControl extends AddressControlTask {
private View anchorView;
// You must send a context
public static void run(Context context, View anchorView, String zipCode, String houseNumber) {
new AddressControl(context, anchorView).execute(zipCode, houseNumber);
}
private AddressControl(Context context, View anchorView) {
super(context);
this.anchorView = anchorView;
}
@Override
public Class<? extends AbstractTask> getTaskClass() {
return getClass();
}
@Override
protected void onPostExecute(final List<Address> result) {
if (result.size() == 0) {
result.add(null);
destroyDialog();
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View view = inflater.inflate( R.layout.control_address_fragment, null );
ImageView okaddress = (ImageView)view.findViewById(R.id.address_ok);
okaddress.setImageResource(R.drawable.clear);
final CustomAlertDialog alertDialog = new CustomAlertDialog(getContext());
alertDialog.setPositiveButton("Ok", new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
alertDialog.setTitle("Wrong");
alertDialog.setText("Address is not correct");
alertDialog.show();
super.onPostExecute(result);
} if(result.size() == 1) {
super.onPostExecute(result);
} else {
destroyDialog();
Context context = getContext();
CustomSelectDialog dialog = new CustomSelectDialog(context, anchorView);
dialog.setOnItemSelectListener(new CustomSelectDialog.OnItemSelectedListener() {
@Override
public void onItemSelected(String text, Object value) {
List<Address> addressList = new ArrayList<>();
addressList.add((Address) value);
onPostExecute(addressList);
}
});
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
onPostExecute(new ArrayList<Address>());
}
});
for(Address address : result) {
dialog.addItem(StringUtils.getAddressText(address), address);
}
dialog.setTitle("Enter true address, please");
dialog.show();
}
}
}