我不太清楚我的問題真的有事情做與listview
。有一個名爲Gleeo Time Tracker一個應用程序,並here有它。當的屏幕視圖按符號"+"
,新項目將被創建,並且您可以通過按"-"
刪除一個項目。更多的是,當我單擊項目左側的記錄按鈕時,背景將會改變。添加新項到ListView
我的問題是,它到底是什麼,一個列表視圖?我怎樣才能做到這一點?謝謝大家!
我不太清楚我的問題真的有事情做與listview
。有一個名爲Gleeo Time Tracker一個應用程序,並here有它。當的屏幕視圖按符號"+"
,新項目將被創建,並且您可以通過按"-"
刪除一個項目。更多的是,當我單擊項目左側的記錄按鈕時,背景將會改變。添加新項到ListView
我的問題是,它到底是什麼,一個列表視圖?我怎樣才能做到這一點?謝謝大家!
你想做什麼,是建立一個自定義的ListView。 這是通過提供一個佈局文件來完成,例如
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent">
<ImageView android:id="@+id/Plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
<TextView android:id="@+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
</LinearLayout>
那麼這種佈局應用到你的ListView的每一行通過覆蓋它的適配器的getView()方法,例如像這樣:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
ImageView plus = (ImageView) v.findViewById(R.id.plus);
icon.setImageDrawable(BrowseActivity.this.getResources().getDrawable(R.drawable.plus));
TextView title = (TextView) v.findViewById (R.id.Browse_FileName);
// add a listener to your button and you're done
return v;
}
閱讀有關開發人員文檔中的列表視圖,這裏是example