2016-03-02 51 views
0

我試過,但我得到的錯誤「的onclick監聽器不能應用在這裏」請幫我傢伙如何聲明按鈕點擊監聽片段切換到活動?

這是我Fragment.java

public class Fragment extends Fragment { 

    public Fragment() { 
     // Required empty public constructor 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_layout, container, false); 
     final Button button = (Button) rootView.findViewById(R.id.payment_info); 
     final Button button1 = (Button) rootView.findViewById(R.id.redeem); 
     final Button button2 = (Button) rootView.findViewById(R.id.make_payment); 
     final Button button3 = (Button) rootView.findViewById(R.id.payment_histories); 


     // Inflate the layout for this fragment 
     return rootView; 
    } 

    @Override 
    public void onAttach(Context context) { 
     super.onAttach(context); 
    } 

    @Override 
    public void onDetach() { 
     super.onDetach(); 
    } 
} 
+0

感謝您接觸到我,我的意思是如何告訴按鈕去片段後,我已經宣佈點擊監聽器E.G. button.setOnClickListener(新View.OnClickListener(){ @覆蓋 公共無效的onClick(視圖v){ >>>>>>>>>我該怎麼辦此處切換到片段 } }); –

回答

0

OnClickListener是一個接口,讓你有不只是延長該片段,但要實施OnClick。

試試這個在您的類的聲明:

public class Fragment extends Fragment implements OnClickListener

希望它能幫助。