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

效果图

 <?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. wxpython中控件对键盘输入无响应的可能原因

    问题描述: 开发环境:Win7 32bit + Python2.7.6 + WxPython 3.0.1-b20140707 开发某初级CAD软件中,需要实现点击TreeCtrl控件的相应选择,实现G ...

  2. 浅谈JavaScript的事件(事件流)

     事件流描述的是从页面中接收事件的顺序.IE的事件流失事件冒泡,而Netspace的事件流失事件捕获. 事件冒泡 IE的事件流叫事件冒泡,即事件开始时,由具体的元素(文档中嵌套层次最深的节点)接收,然 ...

  3. HTTP请求中带有特殊字符"|",返回400错误

    Java平台,服务器是Tomcat8,前端ajax访问服务器时,F12返回400错误,经分析,URL地址中get传参值里面含有“|“, Invalid character found and RFC ...

  4. Micro Frontends

    Micro Frontends - extending the microservice idea to frontend development https://micro-frontends.or ...

  5. 20170225-第三件事:FR0002测试

    第三件事:FR0002测试             MATNR WERKS BERID 800000217 I010               问题,上for all entrys…       1 ...

  6. bashdb bashdebug

    sudo  apt-get install bashdb bashdb  --debug 一.列出代码和查询代码类: l 列出当前行以下的10行 - 列出正在执行的代码行的前面10行 . 回到正在执行 ...

  7. hdu 2680 Choose the best route 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目意思:实质就是给定一个多源点到单一终点的最短路. 卑鄙题---有向图.初始化map时 千万不 ...

  8. Linux系统CentOS下mysql的安装日志

    今天自己捣鼓了一下,在linux系统CentOs6.5下使用源码方式安装和配置mysql,这里记录一下步骤. a) 下载mysql,source版本.Mysql-5.6.20.tar.gz b) 安装 ...

  9. DPI和PPI

    写在前面 各种手机测频机构或者相关资讯老是谈及一个概念:ppi和dpi,通常总会忽略,只是稍微明白,这参数越高,说明屏幕分辨率越高:很长时间都止步如此:但作为一个iOS开发者,岂能止步如此,万一别人问 ...

  10. Watir: 如何处理简单的网页弹出警告框?

    以下是一个很经典的把Watir与AutoIt连接在一起的实例.如果我们对AutoIT了解的更多,处理类似的问题会更加简单.以下实例会判断页面上是否有某“删除”链接,一旦有该链接,就点击,然后点击弹出的 ...