0

ActionBarSherlock のフラグメントとビューに問題があります。

2 つのタブを正常に実装し、タブでフラグメント ビューを開きます。

public class AFragment extends SherlockFragment {

private ImageButton imageButton1;
private ImageButton imageButton2;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Inflate the layout for this fragment


    return inflater.inflate(R.layout.activity_afragment, container, false);



}
}

これは私のコードです。レイアウトには TextView と 2 つの ImageButtons が表示されます。imagebutton = (ImageButton) findViewById(R.id.imagebutton1); のように画像ボタンを宣言したい しかし、それはfindViewByIdでエラーになります。AFragment アクティビティ内のすべての位置で試しましたが、それでも同じエラーが発生します。OnCreate 関数も追加しようとしましたが、これも機能しません...そのビューを機能させるには、どこにコードを配置する必要がありますか? ありがとうございました!

4

1 に答える 1

1

ビューを含む変数を宣言し、必要な宣言と変更を行ってから、ビューを返す必要があります

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.activity_afragment, container, false);
    ImageButton imageButton = (ImageButton) v.findViewById(R.id.imagebutton1); 
    return v;

}
于 2012-07-20T23:06:04.110 に答える