29 个人通讯录列表(一)
个人通讯录列表(一)
MainActivity.java
package com.example.mybooks; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends AppCompatActivity { //创建ListView控件 private ListView mylistview; //定义一个适配器 private ArrayAdapter<String> myAdapter; //定义一个数组,用于ListView的数据源 private String[] books = {"大洋","念念","翠花","同同","鼬","带土","止水",}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //使用ListView展示通讯录 //初识化控件 mylistview = findViewById(R.id.mylistview); //创建适配器(参数1:上下文,参数2:列表项布局文件,参数3:数据源) myAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,books); //设置适配器到ListView mylistview.setAdapter(myAdapter); } }