android--listview练习

java代码

 1 package com.example.myapplication.listview;
 2   
 3 import android.content.Context;
 4 import android.view.LayoutInflater;
 5 import android.view.View;
 6 import android.view.ViewGroup;
 7 import android.widget.BaseAdapter;
 8 import android.widget.TextView;
 9   
10 import java.text.SimpleDateFormat;
11 import java.util.Date;
12 import java.util.Locale;
13 import java.util.TimeZone;
14   
15 import com.example.myapplication.R;
16   
17 public class MylistAdapter extends BaseAdapter{
18      private Context context1;
19      private LayoutInflater layoutInflater1;
20   
21      public MylistAdapter (Context context){
22       this.context1=context;
23       layoutInflater1=LayoutInflater.from(context);
24      }
25     public int getCount() {
26         return 5;
27     }
28   
29     @Override
30     public Object getItem(int i) {
31         return null;
32     }
33   
34     @Override
35     public long getItemId(int i) {
36         return 0;
37     }
38     static class ViewHolder{
39          public TextView tv_title,tv_wupin,tv_time;
40     }
41     @Override
42     public View getView(int i, View v, ViewGroup viewGroup) {
43          ViewHolder holder =null;
44          if (v==null){
45               v = layoutInflater1.inflate(R.layout.activity_list_item,null);
46               holder = new ViewHolder();
47               holder.tv_time=v.findViewById(R.id.tv_time);
48              holder.tv_wupin=v.findViewById(R.id.tv_wupin);
49              holder.tv_title=v.findViewById(R.id.tv_title);
50               v.setTag(holder);
51          }else {
52              holder= (ViewHolder) v.getTag();
53          }
54         SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
55         String date = sDateFormat.format(new java.util.Date());
56          holder.tv_title.setText("用户你好");
57          holder.tv_time.setText(date);
58          holder.tv_wupin.setText("请选择你喜爱的物品");
59         return v;
60     }
61 }

xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="horizontal"
 6     android:padding="15dp">
 7       
 8     <ImageView
 9         android:layout_width="100dp"
10         android:layout_height="100dp"
11         android:scaleType="fitXY"
12         android:background="@drawable/xiaohuli"/>
13     <LinearLayout
14         android:layout_width="match_parent"
15         android:layout_height="wrap_content"
16         android:orientation="vertical">
17         <TextView
18             android:id="@+id/tv_title"
19             android:layout_width="match_parent"
20             android:layout_height="wrap_content"
21             android:text="用户你好"
22             android:gravity="center"
23             android:textSize="30dp"
24             android:textColor="#000000"
25             android:layout_marginLeft="15dp"/>
26         <TextView
27             android:id="@+id/tv_time"
28             android:layout_width="wrap_content"
29             android:layout_height="wrap_content"
30             android:layout_marginLeft="15dp"
31             android:text="现在时间为:2000-11-5"
32             android:textSize="26dp"
33             />
34         <TextView
35             android:id="@+id/tv_wupin"
36             android:layout_width="wrap_content"
37             android:layout_height="wrap_content"
38             android:layout_marginLeft="15dp"
39             android:gravity="center"
40             android:text="请选择你喜爱的物品"
41             android:textSize="26dp"
42             />
43           
44     </LinearLayout>
45   
46 </LinearLayout>

 

android--listview练习

上一篇:axios入门(1)—— axios常用五种请求方法介绍(get、post、put、patch、delete)


下一篇:C盘优化之桌面移动法,拯救你爆满的C盘!