移动开发第二次作业——Activity页面跳转

移动开发第二次作业——Activity页面跳转

一、编辑详情页面

页面设计布局效果如下:

在这里插入图片描述

布局介绍:

顶部为返回箭头,用于点击返回上一页;分享图标用于分享到社交软件

新闻标题TextView从上一页得到数据展示,发布人id,签名等都从上一页得到数据

正文部分以及头像,从数据库中获得(目前使用伪数据)。

布局代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/homepage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/back"
            android:layout_width="32dp"
            android:layout_height="32dp"
            app:srcCompat="@drawable/back" />

        <ImageView
            android:id="@+id/share"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_marginLeft="325dp"
            app:srcCompat="@drawable/share" />
    </LinearLayout>

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="新闻标题"
        android:textColor="@color/black"
        android:textSize="28sp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:textStyle="bold" />

    <LinearLayout
        android:id="@+id/home_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/profile_photo"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="left"
            app:srcCompat="@drawable/me_1" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            >
            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textSize="18sp"
                android:textStyle="bold"
                android:text="发布人id" />
            <TextView
                android:id="@+id/status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="发布人签名"
                />
        </LinearLayout>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        >
        <TextView
            android:id="@+id/essay"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="top"
            android:text="@string/essay"
            />
    </LinearLayout>
</LinearLayout>

二、在原Fragment页面(首页)添加点击跳转功能

由于之前以及在Adapter中写好点击事件接口,所以只需要在FragmentWx中实现接口的方法即可:得到调用点击方法的item的position然后将对应的数据传递给下一个activity。

//private List<MegList> data;


myAdapter = new MyAdapter(data,view.getContext(), new MyAdapter.MyItemClicklistener() {
    @Override
    public void onClick(int position) {
        //Toast.makeText(view.getContext(), "更多内容有待开发", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(getActivity(), HomeActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("title", data.get(position).getTitle());
        bundle.putString("userName",data.get(position).getUsername());
        bundle.putString("status",data.get(position).getStatus());
        intent.putExtras(bundle);
        //携带position的调用可以清楚的知道是哪个item调用的详情页
        startActivityForResult(intent,position);
    }
});

二、在详情页数据展示

在详情页中获取传递过来的数据,并添加返回按钮的点击事件:点击后调用finish()方法结束这个activity回到上一页

private void createData(){
    Bundle extras = getIntent().getExtras();
    String heading = extras.getString("title");
    String userId = extras.getString("userName");
    String userStatus = extras.getString("status");

    title.setText(heading);
    userName.setText(userId);
    status.setText(userStatus);
    backImg.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();

        }
    });
}

至此页面跳转完成。
在这里插入图片描述

三、效果展示

在这里插入图片描述

四、实体类说明

即数据形式,将消息的类别、消息标题、发布人id、签名封装到一个对象中。

public class MegList {
    //数据本身
    private String title;
    //组号
    private String group;

    //id
    private String username;
    //签名
    private String status;
    
    //constructor、get、set

}

五、码云地址

点赞关注

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值