Java Android片段代码问题

Java Android片段代码问题,java,android,android-listview,android-fragments,Java,Android,Android Listview,Android Fragments,我想知道如何让下面的代码与我的项目一起工作,从而将两者结合起来,使其能够工作。我在应用程序中实现了一个导航抽屉 第一个使用片段的Java代码: import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class PagesFragment ex

我想知道如何让下面的代码与我的项目一起工作,从而将两者结合起来,使其能够工作。我在应用程序中实现了一个导航抽屉

第一个使用片段的Java代码:

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class PagesFragment extends Fragment {

public PagesFragment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_pages, container, false);

    return rootView;
}
}
使用活动的第二个Java代码:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AppointmentActivity extends Activity {
Button sendEmail;
EditText msg;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.appointment_layout);

    sendEmail = (Button) findViewById(R.id.sndBtn);
    sendEmail.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            msg = (EditText) findViewById(R.id.msgTxt);
            String message = msg.getText().toString();
            sendEmail(message);
        }

    });
}

protected void sendEmail(String message) {

    String[] to=new String[]{"Shop@email.com"};
    String subject=("Shop Appointment");
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, message);
    emailIntent.setType("message/rfc822");
    startActivity(Intent.createChooser(emailIntent, "Gmail"));
}
}

我自己也尝试过将这两种代码结合起来,但我没有太多与android打交道的经验,不知道如何让这两种代码同时工作,而不会给我带来压力。一切都会有帮助的

要组合这些代码,您需要像声明
片段活动一样声明
活动
(它将“宿主”您的
片段
)。请参见以下答案:

希望这有帮助