Android开发,从Fragment中跳转到其他Activity后只显示空白的活动

准备实现的功能是点击售后服务后跳转到Guarantee这个类中。
public class ThirdFragment extends Fragment implements View.OnClickListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.third_fragment, container, false);
LinearLayout guaranteell = (LinearLayout) view.findViewById(R.id.serviceGuaranteeId);
guaranteell.setOnClickListener(this);
return view;
}
@Override
public void onClick(View view){
Intent intent = new Intent(getActivity(), Guarantee.class);
startActivity(intent);

        Guarantee.class的代码如下

```public class Guarantee extends AppCompatActivity {

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View view = inflater.inflate(R.layout.activity_guarantee, container, false);
    //setContentView(R.layout.activity_guarantee);
    return view;
}

}```

图片说明

图片说明

你的ThirdFragment 里面的onClick方法没有指定id,用view.getId()获取之后确定是哪一个view的点击事件。

onClick里面可以 switch(view.getId()){ case:选择你的view的id } 然后在case下面编写具体的响应事件

http://blog.csdn.net/myGFZ/article/details/53400170

public class Guarantee entends AppCompatActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_guarantee);
    }

}

2个问题:1、点击事件需要ID判断 2、在activity中需要重写onCreate方法。你的做法是用的fragment的做法

继承AppCompatActivity,应该重写onCreate方法,不是onCreateView

可以的话,把你的项目发到我邮箱1444089871@qq.com,这样看得比较清楚一点。

为什么不直接在oncreate方法里面直接setContentView(),界面不就出来了吗