【Android】利用ArrayAdapter 创建ListView

利用ArrayAdapter 创建ListView
目录
arrayadapter.xml
array_item.xml
MainActivity
演示
新建两个layout的xml
arrayadapter.xml


【Android】利用ArrayAdapter 创建ListView
文章图片

array_item.xml

【Android】利用ArrayAdapter 创建ListView
文章图片

MainActivity
package com.example.administrator.android20200322; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends AppCompatActivity {ListView myList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.arrayadapter); ListView list1 = (ListView)findViewById(R.id.list1); String[] arr1 = {"C语言","C++","QT","Android","Java","GTK"}; ArrayAdapter adapter1 = new ArrayAdapter(this,R.layout.array_item,arr1); list1.setAdapter(adapter1); } }

演示
【【Android】利用ArrayAdapter 创建ListView】【Android】利用ArrayAdapter 创建ListView
文章图片

    推荐阅读