安卓:启动内片段活动片段

2023-09-12 05:13:41 作者:岁月漫长,还好你一直都在

我是新android开发。现在,我有卡在我的行动吧。我创建类的片段。我的第一个类只有一个按钮当前。我会更晚加。我尝试启动这个类中的一个活动,当你点击一个按钮,但它不会工作...它只是崩溃这里的code:

I am new to android development. Right now I have tabs in my action bar. I have created classes for those fragments. My first class has only one button currently. I'll add more later. I try to start an activity within this class when you click a button, but it won't work...It just crashes Here's the code:

package com.cydeon.plasmamodz;

import com.cydeon.plasmamodz.R;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

  public class ThemeFragment extends Fragment {

   @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.theme_frag,
            container, false);
    Button button = (Button) view.findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(getActivity(), Themes.class);
            getActivity().startActivity(intent);
        }
    });

    return view;
}}

我没有在清单中定义的主题类。我不知道我在做什么错了,真的可以使用一些帮助。正如我所说的,我只有15新本。

I did define the themes class in the manifest. I'm not sure what I'm doing wrong, and could really use some help. As I said, I'm only 15 and new to this.

推荐答案

我的code是罚款。我开始在我的ThemeFragment类进行主题类,但它做一个新的类,忘了删除。现在一切工作正常。

My code is fine. I began to make the Themes class within my ThemeFragment class, but then made it a new class, and forgot to delete it. Everything works fine now.