zoukankan      html  css  js  c++  java
  • Adapter

    上面就是Adapter以及继承结构图了,接着我们介绍一下实际开发中还用到的几个Adapter吧!

    • BaseAdapter抽象类,实际开发中我们会继承这个类并且重写相关方法,用得最多的一个Adapter!
    • ArrayAdapter:支持泛型操作,最简单的一个Adapter,只能展现一行文字~
    • SimpleAdapter:同样具有良好扩展性的一个Adapter,可以自定义多种效果!
    • SimpleCursorAdapter:用于显示简单文本类型的listView,一般在数据库那里会用到,不过有点过时, 不推荐使用!

    其实一个BaseAdapter就够玩的了,至于其他的,实际开发中用得不多,后面用到在讲解~

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
            <ListView
                android:id="@+id/ListView_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </ListView>
        </LinearLayout>
    
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
            android:layout_weight="1">
        <ListView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ListView_id2">
        </ListView>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">
            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/ListView_id3">
            </ListView>
    
        </LinearLayout>
     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            lv = (ListView) findViewById(R.id.ListView_id);
            String[] str = {"哈哈", "呵呵", "嘿嘿", "吼吼", "咔咔", "啦啦"};
            ArrayAdapter<String> arrayAdapter= new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, str);
            lv.setAdapter(arrayAdapter);
    
            lv2 = (ListView) findViewById(R.id.ListView_id2);
            Integer[] i = {1, 2, 3, 4, 5, 6, 7, 8, 9};
            ArrayAdapter<Integer> arrayAdapter2= new ArrayAdapter<Integer>(this, android.R.layout.simple_expandable_list_item_1, i);
            lv2.setAdapter(arrayAdapter2);
    }

  • 相关阅读:
    [HAOI2008]硬币购物
    [NOI2006]网络收费
    [HNOI2014]米特运输
    Codeforces Round #536 (Div. 2)
    [洛谷P3931]SAC E#1
    [洛谷P1402]酒店之王
    [洛谷P4174][NOI2006]最大获利
    [CF1082G]Petya and Graph
    [CF1095F]Make It Connected
    [CF1083B]The Fair Nut and Strings
  • 原文地址:https://www.cnblogs.com/maogefff/p/8151596.html
Copyright © 2011-2022 走看看