ArrayAdapter

来源:互联网 发布:美工绩效考核 编辑:程序博客网 时间:2024/05/16 17:01

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MainActivity" >    <ListView        android:id="@+id/myListView"        android:layout_width="match_parent"        android:layout_height="wrap_content" /></LinearLayout>

list_view.xml

<?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" >  <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/btn_keyboard_key_trans_pressed" />    <TextView        android:id="@+id/tv_content"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="我是文本"        android:textSize="24sp" /></LinearLayout>

MainActivity.java

package com.demo.arrayadapter;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import android.app.Activity;public class MainActivity extends Activity {private ListView myListView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);myListView = (ListView) findViewById(R.id.myListView);myListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_view, R.id.tv_content, new String[]{"功能1","功能2","功能3"}));}}


该ArrayAdapter局限在于,只能更改文本内容,无法更改图片

效果图:



0 0
原创粉丝点击