2016-12-23 1 views
-1

ImageViewsetImageResourceと設定しようとしていますが、機能しません。何もエラーはありません。 logcatは正常に見えます。私はと呼ばれる別のレイアウトからImageViewを宣言することを考えるとsetImageResourceが機能しない

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); 
} 

は、ここに私のコードです。別のレイアウトのイメージを設定するために2つのレイアウトを膨張させると問題になりますか?

ここに間違いがありますか?

+0

あなたはinflatとイメージリソースを設定した後、メインレイアウトに別のビューレイアウトを追加しますか? –

+0

いいえ、別のビューを最初に展開してからイメージを設定します。 ビュービュー= inflater.inflate(R.layout.fragment_item_list_request、container、false); setHasOptionsMenu(true); 他のビューを表示= inflater.inflate(R.layout.style_fragment_list_request、container、false); imgView =(CircleImageView)anotherView.findViewById(R.id.listPhoto); imgView.setImageResource(R.drawable.pastel_red); } – Borom1r

+0

別のビューを追加する必要があります。そうでない場合は、表示されません。 –

答えて

0
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); 
} 
0

あなたが代わりにこれを行う場合:

View anotherView = inflater.inflate(R.layout.style_fragment_list_request,null,false); 
+0

まだ動作していません – Borom1r

0

anotherViewを返す声明。 onCreateView()にがありません。