android.content.res.Resources$NotFoundException: Resource ID #0x0
import android.os.Bundle; import android.view.View; import android.app.Fragment; import android.view.ViewGroup; import android.widget.TextView; import android.widget.ImageView; import android.view.LayoutInflater; import android.graphics.drawable.Drawable; import android.support.v4.content.res.ResourcesCompat; import static android.content.res.Resources.*; public class FragmentOne extends Fragment { ImageView ivIcon; TextView tvItemName; public static final String IMAGE_RESOURCE_ID = "iconResourceID"; public static final String ITEM_NAME = "itemName"; public FragmentOne() {} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_layout_one, container, false); ivIcon = (ImageView) view.findViewById(R.id.frag1_icon); tvItemName = (TextView) view.findViewById(R.id.frag1_text); tvItemName.setText(getArguments().getString(ITEM_NAME)); ivIcon.setImageDrawable(view.getResources().getDrawable(getArguments().getInt(IMAGE_RESOURCE_ID),view.getContext().getTheme())); return view; } }
String
int
R.drawable.iconResource
Quote:Open for correction, anytime.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)