我试图添加一个按钮到我的片段布局,但它说,方法findViewByid
无法解析。我在片段中的onCreateView
方法中实现它。为什么它给我这个错误?在片段中添加一个按钮?
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.View;
import android.widget.Button;
public class extra extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Button myButton = (Button) findViewById(R.id.my_button);
return inflater.inflate(R.layout.extra, container, false);
}
}
这是因为你的类没有一个findByViewId方法 – Stultuske
检查我的解决方案@asdddd –