首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从数据库(REST)查看数据

如何从数据库(REST)查看数据
EN

Stack Overflow用户
提问于 2018-05-24 04:10:44
回答 1查看 34关注 0票数 0

海底导航SS我已经用android在我的应用程序中做了底部导航。所以,我想在我的一个片段中创建一个按钮。我该怎么做呢?有视频参考资料吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-24 04:51:01

这很容易,也不太难,只需将按钮放在片段布局中,然后在片段中创建实例之后,将侦听器放置到特定按钮中,如以下所示。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/mBtnPresent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>



@SuppressLint("ValidFragment")
public class FragmentTest extends Fragment {


    private View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_test, container, false);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        AppCompatButton mBtnPresent=view.findViewById(R.id.mBtnPresent);
        mBtnPresent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //perform action what you want on button click
            }
        });

    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50500822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档