注意:课程设计只为完成任务,不做细节描述~

效果图

 <?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="asad"
>
</ListView> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/img_ico"
android:src="@mipmap/x2017612"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/text1"
android:layout_toRightOf="@id/img_ico"
android:text="miemie"
android:textSize="16sp"
android:textColor="#0ccfff"/>
<TextView android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/text2"
android:layout_below="@id/text1"
android:layout_alignLeft="@id/text1"
android:text="xxxxx"
android:textSize="16sp"
android:textColor="#0ccfff"
/>
</RelativeLayout>
 package com.example.myapplication;

 import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView; /**
* Created by 樱花落舞 on 2017/6/12.
*/ public class MyAdapter extends BaseAdapter {
private String names[], contents[];
private int images[];
//上下文
private Context context; public MyAdapter(String names[], String contents[], int images[],Context context) {
this.names = names;
this.contents = contents;
this.images = images;
this.context=context;
} //获取列表总数
@Override
public int getCount() {
return names.length;
} //获取单个item
@Override
public Object getItem(int position) {
return names[position];
} //获取itemid
@Override
public long getItemId(int position) {
return position;
} //得到item视图
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.item,null);
ImageView image = (ImageView) view.findViewById(R.id.img_ico);
TextView name = (TextView) view.findViewById(R.id.text1);
TextView content = (TextView) view.findViewById(R.id.text2); image.setImageResource(images[position]);
name.setText(names[position]);
content.setText(contents[position]); return view;
}
}
 package com.example.myapplication;

 import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
/*
listview的使用
在布局中准备控件
在java代码中声明实例化
准备数据源
创建适配器
加载适配器 */
public class MainActivity extends AppCompatActivity {
//声明控件
private ListView listView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView= (ListView) findViewById(R.id.listview); String names[]={"xh","xhh","xhhh","xhhhh"};
String contents[]={"Max","max","min","Min"};
int images[]={R.mipmap.a,R.mipmap.b,R.mipmap.c,R.mipmap.d};
MyAdapter adapter =new MyAdapter(names,contents,images,MainActivity.this);
listView.setAdapter(adapter);
}
}

Android课程设计第四天ListView运用的更多相关文章

  1. Android课程设计第五天欢迎界面(滑动)和图形选择

    注意:课程设计只为完成任务,不做细节描述~ 滑动界面 package com.example.myapplication; import android.content.Intent; import ...

  2. Android课程设计第二天界面排版

    注意:课程设计只为完成任务,不做细节描述~ 老师叫我们做一个这个样子,然后.. <?xml version="1.0" encoding="utf-8"? ...

  3. Android课程设计第六天欢迎界面(跳转)

    注意:课程设计只为完成任务,不做细节描述~ package com.example.myapplication; import android.app.Activity; import android ...

  4. Android课程设计第三天帧动画区间动画

    注意:课程设计只为完成任务,不做细节描述~ 点火是帧动画,发射是区间动画,于是 <?xml version="1.0" encoding="utf-8"? ...

  5. Android课程设计第一天Android Studio安装

    注意:课程设计只为完成任务,不做细节描述~ 学校有一个Android的课设,所以顺便把Android Studio安装了上去. 实际上安装过程并不复杂,只有几个地方需要注意~ 安装包可以去http:/ ...

  6. Android课程设计——博学谷1.0

    本文讲述了如何应用大三下学期智能移动终端开发技术课程所学知识,完成包含服务器端.客户端程序的应用——博学谷登录模块的开发,结合java语言基本知识,例如:字符串.列表.类.数据库读写等,设计.实现一个 ...

  7. 一培训机构设计的学习android课程内容:供大家参考

    转自:http://www.cnblogs.com/csj007523/archive/2011/06/16/2082682.html 一培训机构设计的学习android课程内容:供大家参考 第一阶段 ...

  8. 《Android群英传》读书笔记 (2) 第三章 控件架构与自定义控件详解 + 第四章 ListView使用技巧 + 第五章 Scroll分析

    第三章 Android控件架构与自定义控件详解 1.Android控件架构下图是UI界面架构图,每个Activity都有一个Window对象,通常是由PhoneWindow类来实现的.PhoneWin ...

  9. Android图表库MPAndroidChart(十四)——在ListView种使用相同的图表

    Android图表库MPAndroidChart(十四)--在ListView种使用相同的图表 各位好久不见,最近挺忙的,所有博客更新的比较少,这里今天说个比较简单的图表,那就是在ListView中使 ...

随机推荐

  1. inheritance super overrides printMethod in Superclass override重写父方法

    Core Java Web Page http://horstmann.com/corejava.html [ inheritance ] package v1ch05.inheritance; im ...

  2. Random 类生成随机数

    Random类 (java.util) Random类中实现的随机算法是伪随机,也就是有规则的随机.在进行随机时,随机算法的起源数字称为种子数(seed),在种子数的基础上进行一定的变换,从而产生需要 ...

  3. CocoaPods初体验

    之前没用过cocoapods,但是新项目需要用到. 安装cocoapods: 按照官方的: $ sudo gem install cocoapods    // 但是什么都没有发生 升级gem $ s ...

  4. react native camera

    最近在尝试用react native camera iOS版本很方便就调试通过了,react的试用非常方便 android版本要单独试用fork的 屏蔽了lint的报错后也可以调试通过 参考这篇文章填 ...

  5. git apply、git am打补丁.diff 和 .patch【转】

    本文转载自:https://www.jianshu.com/p/e5d801b936b6 前提: 生成patch: git format-patch -M master 生成指定patch,0163b ...

  6. HDU3085 Nightmare Ⅱ —— 双向BFS + 曼哈顿距离

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3085 Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Other ...

  7. YTU 2453: 我想有套北京的房

    2453: 我想有套北京的房 时间限制: 1 Sec  内存限制: 128 MB 提交: 796  解决: 289 题目描述 小原是一个软件工程师,名叫原黛玛,他在北京工作.现在有一套房子,价格200 ...

  8. 关于苹果iPhone手机对页面margin属性无效的解决方法一(如有错误,请留言批评)

    这个问题,是在给商城网站底部footer设置margin属性的时候发现的,先把出现问题的截图发出来看一下 ​安卓手机,打开正常 ​iphone6 p 打开出现的问题(无视margin-bottom:6 ...

  9. 【转】Java数字抽奖游戏核心代码

    1. [代码][Java]代码    package com.luiszhang.test; import java.util.Arrays; /** * NumberLotteryGame * 一个 ...

  10. codeforces 440C. One-Based Arithmetic 解题报告

    题目链接:http://codeforces.com/problemset/problem/440/C 题目意思:给出一个数你,问需要用到的1来组成这个数的最少数量是多少. 我一开始对每个数只从 “+ ...