<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                我是安卓的初學者,最近在學習ListView的內容,LiatView以垂直方式顯示各個列表項,而他的列表項由Adapter提供。Adapter常用的是4種,下面是我比較喜歡用的BaseAdapter,感覺BaseAdapter的拓展性非常高。下面貼上一個我的代碼以及寫寫我對這段代碼的理解,作為這兩天的學習筆記吧。 首先是兩個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="vertical"> <ListView android:id="@+id/myView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> ~~~ ~~~ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/filePic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:layout_alignParentLeft="true" /> <TextView android:id="@+id/fileName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello" android:layout_toRightOf="@id/filePic" /> </RelativeLayout> ~~~ 上面第一個xml只是定義了一個ListView,第二個xml定義了每個列表項的顯示內容。 下面是我的java代碼 ~~~ public class MainActivity extends Activity { public ListView myList ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myList = (ListView)findViewById(R.id.myView); //自定義的一個Adapter,繼承BaseAdapter MyAdapter adapter = new MyAdapter(this); //設置Adapter myList.setAdapter(adapter); } public class MyAdapter extends BaseAdapter { private Context mContext; public MyAdapter (Context context) { this.mContext=context; } //該方法返回值控制該ListView包括多少個列表項 @Override public int getCount() { return 15; } //返回值決定列表項的內容 @Override public Object getItem(int position) { return null; } //返回值決定第position處的列表項的id @Override public long getItemId(int position) { return position; } //返回值決定第position處的列表組件 @Override public View getView(int position, View convertView, ViewGroup parent) { //自定義的一個類,存儲每個列表項的內容 ViewHolder holder; //如果傳進來的組件為空 if (convertView == null) { //創建一個holder holder = new ViewHolder(); //獲取xml組件的內容 convertView = LayoutInflater.from(mContext).inflate( R.layout.file_item,null); //把獲取的組件賦給holder holder.myImage = (ImageView)convertView.findViewById(R.id.filePic); holder.myText = (TextView)convertView.findViewById(R.id.fileName); //把holder和convertView關聯 convertView.setTag(holder); } else { holder = (ViewHolder)convertView.getTag(); } return convertView; } }; //自定義的靜態類,里面的內容為每個列表項包括的內容 public final class ViewHolder { ImageView myImage; TextView myText; } } ~~~ 寫的比較挫,只能算是基本了解了BaseAdapter的運作過程,但是還有很多東西未能清楚,下面一些比較重要的點 1)BaseAdapter里面的button 2)BaseAdapter里面的checkBox 3)明白BaseAdapter的內存管理以及優化 下一步我會重點了解這三個問題。下一篇日志將會對部分問題進行解釋
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看