ListView用法,适配器的简单使用代码
package com.example.twj.testyixue; import android.app.Activity; import android.os.Bundle; import android.widget.ListView; /** * Created by t'w'j on 2020/4/18. */ public class ListViewDemoActivity extends Activity { private ListView mphoneBookListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_listview_demo); mphoneBookListView=(ListView)findViewById(R.id.list_view); PhoneBookAdapter phoneBookAdapter=new PhoneBookAdapter(ListViewDemoActivity.this); mphoneBookListView.setAdapter(phoneBookAdapter); } }
<?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" android:orientation="horizontal" android:padding="15dip" > <TextView android:id="@+id/time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:gravity="center" /> </RelativeLayout>