Reputation: 155
I'm about to set an ImageView
with setImageResource
, but it's not working. nothing error too. and the logcat seems fine.
Here is my code :
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item_list_request, container, false);
setHasOptionsMenu(true);
View anotherView = inflater.inflate(R.layout.style_fragment_list_request,container,false);
imgView = (CircleImageView)anotherView.findViewById(R.id.listPhoto);
imgView.setImageResource(R.drawable.pastel_red);
}
Considering that I called and declare the ImageView
from another layout. Is at problem if I inflate 2 layouts just for set image for another layout ?
Anything wrong here?
Upvotes: 1
Views: 3272
Reputation: 1615
What if you do this instead:
View anotherView = inflater.inflate(R.layout.style_fragment_list_request,null,false);
Upvotes: 0
Reputation: 3798
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item_list_request, container, false);
setHasOptionsMenu(true);
return view;
}
public void onActivityCreated(){
ViewGroup layout = (ViewGroup) getView().findById(R.id.layout_another_view); // need layout for anotherView in fragment_item_list_request.xml
View anotherView = inflater.inflate(R.layout.style_fragment_list_request,container,false);
imgView = (CircleImageView)anotherView.findViewById(R.id.listPhoto);
imgView.setImageResource(R.drawable.pastel_red);
layout.addView(anotherView);
}
Upvotes: 1