zoukankan      html  css  js  c++  java
  • 4.10

     实现代码:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
    
    
        <TextView
            android:id="@+id/list_name"
            android:layout_width="0dp"
            android:layout_height="64dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="小猪"
            android:textColor="#0000FF"
            android:textSize="18sp" />
    
        <TextView
            android:id="@+id/list_phone"
            android:layout_width="0dp"
            android:layout_height="64dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="13798989898"
            android:textColor="#EA5C4D"
            android:textSize="18sp" />
    
    
    </LinearLayout>
    MainActivity.java:
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            ListView list_test = (ListView) findViewById(R.id.list_test);
            //读取联系人
            Cursor cursor = getContentResolver()
                    .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
            SimpleCursorAdapter spcAdapter = new SimpleCursorAdapter(this,R.layout.list_item,cursor,
                    new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER},
                    new int[]{R.id.list_name,R.id.list_phone});
            list_test.setAdapter(spcAdapter);
        }
    }
     
  • 相关阅读:
    windows编程学习笔记
    自学JAVA-12:MySQL数据库
    自学JAVA-11:IO流
    自学JAVA-10:集合
    自学JAVA-9:基本类常用方法整理
    自学JAVA-8:异常
    自学JAVA-7:多态
    自学JAVA-6:继承
    自学JAVA-5:修饰符、对象初始化
    自学JAVA-4:方法、对象、类、属性
  • 原文地址:https://www.cnblogs.com/20193898liufa/p/14909522.html
Copyright © 2011-2022 走看看