2012-07-20 5 views
0
내가 ActionBarSherlock의에 조각과 전망에 문제가있어

는 :안드로이드 ActionBarSherlock의 탭 : 조각보기

나는 성공적으로이 개 탭을 구현했습니다 및 탭 내 조각보기를 엽니 다.

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 개의 ImageButton을 보여줍니다. imagebutton = (ImageButton)과 같은 이미지 단추를 선언하고 싶습니다. findViewById (R.id.imagebutton1); 하지만 그 findViewById에서 오류가 발생합니다. AFragment Activity 내의 모든 위치에서 시도했지만 여전히 같은 오류가 있습니다. 또한 OnCreate 함수를 추가하려고 시도 했는데도 작동하지 않습니다 ... 그래서 뷰가 작동하도록 코드를 어디에 두어야합니까? 고맙습니다!

답변

1

당신은 당신이 원하는 선언과 modifiations을,보기를 포함하는 변수를 선언 한 다음보기

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; 

} 
+0

WOW에게 반환해야합니다! 친애하는 친절 선생님, 이것은 나를 위해 일했습니다! 감사합니다. 당신은 내게 4 시간 전력을 구해 줬어 :) (불행히도 나는 명성이 없어서 투표를 할 수 없다 ...) – moritzg