温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android 学习--ListView 的使用(二)

发布时间:2020-05-12 23:10:41 来源:网络 阅读:230 作者:uncom2005 栏目:移动开发

 基于ArrayAdapter 创建ListView

程序清单


listview2.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">     <ListView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/list1"         android:divider="#0f0"         android:dividerHeight="3px"         android:footerDividersEnabled="false"          /> </LinearLayout>

MainActivity.java

package xiaocool.net.listviewtest; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends ActionBarActivity {    private ListView list;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.listview2);         list=(ListView)this.findViewById(R.id.list1);         //定义一个数组         String arr[]={"校酷网络1","校酷网络2","校酷网络3","校酷网络4","校酷网络5"};         //将数组包装成ArrayAdapter         ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.array_item,R.id.textView,arr);         list.setAdapter(adapter);     } }

array_item..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">     <TextView         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:id="@+id/textView"         android:textSize="20sp"         android:textColor="#f0f"         android:padding="20px"         /> </LinearLayout>

Android 学习--ListView 的使用(二)

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI