Listview和Adapter作业

安卓作业:使用ListView和自定义Adapter完成列表信息显示

1.XML主布局文件代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cn.edu.niit.liebiaoxinxixianshi.QiuActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/out"
>

</LinearLayout>

</RelativeLayout>
2.四个TextView布局:
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
android:scrollbars="vertical"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/List1"
android:text="@string/name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/List2"
android:text="@string/age"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/List3"
android:text="@string/mail"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/List4"
android:text="@string/address"/>
3.定义String<resources>
    <string name="app_name">liebiaoxinxixianshi</string>
<string name="list">目录</string>
<string name="name">姓名</string>
<string name="age">年龄</string>
<string name="mail">邮箱</string>
</resources>
4.java文件
package com.example.ershiqiapplication;

import android.app.Fragment;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fragment fragment=new ListViewFragment();
transaction.add(R.id.out,fragment);
transaction.commit();//显示fragment
}
}
增加数据,数据准备:
datas.add(new Classinfo("姓名:蔡志坤","年龄:25","邮箱:ffczk86@gmail.com","地址:厦门市"));
datas.add(new Classinfo("姓名:李杰华","年龄:25","邮箱:aa@bb.com","地址:漳州市"));
datas.add(new Classinfo("姓名:张亮","年龄:25","邮箱:cc@gmail.com","地址:厦门市"));
datas.add(new Classinfo("姓名:陈旭","年龄:25","邮箱:ccadd@gmail.com","地址:厦门市"));
datas.add(new Classinfo("姓名:刘玄德","年龄:25","邮箱:ffczk86@gmail.com","地址:福州市"));

自定义Adapter 通过Adapter来获得数据

 



转载于:https://www.cnblogs.com/qiuqiuhui/p/6797028.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值