任何人都可以告诉我,为什么会显示此错误(或者甚至有更好的解决方案)?
我是新来的Java(和Android)的发展,所以我真的不知道我的错 我的代码:方法不会覆盖超类的方法
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class select_type extends Fragment {
public select_type() {
// Required empty public constructor
}
@Override //<--- Cause the ERROR
public View onCreateView(View view, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
return inflater.inflate(R.layout.fragment_select_type, container, false);
Button btn = (Button) view.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
noVIP TextFragment = new noVIP();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, TextFragment);
transaction.addToBackStack(null);
transaction.commit();
}
});
return view;
}
}
好了,但现在,我怎样才能使'按钮BTN =(按钮)view.findViewById(R.id.btn)'? – NiklasZeroZero
@NiklasZeroZero:将'inflater.inflate(...)'结果赋值给一个局部变量。随意调用这个'View''view''。然后,在'view'上调用'findViewById()'。 – CommonsWare