I have a problem when creating dynamically an imageview from a fragment. Here is the code:
public class Fragment_Categorize extends Fragment implements View.OnDragListener, View.OnLongClickListener {
Context context;
public Fragment_Categorize() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment__categorize, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
context = getActivity().getApplicationContext();
ImageView imm = new ImageView(context);
imm.setBackgroundResource(R.drawable.apple);
ImageView black = (ImageView) getActivity().findViewById(R.id.black);
black.setOnLongClickListener(this);
The imageview that is created dynamically returns -1 on a getId() where the static one works fine. Any reason why?