相关疑难解决方法(0)

如何在Android中的片段中单击按钮打开片段

我在HomeFragment上有一些按钮,我想在片段上点击按钮打开片段.像导航这样的东西.我正在尝试使用波纹管代码,但没有奏效.请帮忙 !我对android很新,并且正在尝试学习新东西.

这是我的代码

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 HomeFragment extends Fragment {

    public HomeFragment(){}



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

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

        Button aboutBtn = (Button) rootView.findViewById(R.id.aboutusButton);
        Button phonebookBtn = (Button) rootView.findViewById(R.id.phbookButton);
        Button schemeBtn = (Button) rootView.findViewById(R.id.schemeButton);
        Button loanBtn = (Button) rootView.findViewById(R.id.loanButton);
        Button serviceBtn = (Button) rootView.findViewById(R.id.serviceButton);
        Button devBtn = (Button) rootView.findViewById(R.id.devButton);

        aboutBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v)
            {
                // …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-fragments

19
推荐指数
1
解决办法
6万
查看次数