Java tutorial
//package com.java2s; import android.app.Activity; import android.graphics.drawable.Drawable; import android.view.View; import android.widget.TextView; public class Main { public static void updateRightImgTitle(Activity activity, int viewId, int txtRes, int imgRes) { View view = activity.findViewById(viewId); if (view == null) { return; } if (view instanceof TextView) { view.setVisibility(View.VISIBLE); ((TextView) view).setText(activity.getString(txtRes)); Drawable drawable = activity.getResources().getDrawable(imgRes); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); ((TextView) view).setCompoundDrawables(null, drawable, null, null); } } }