簡體   English   中英

帶有復選框,imageview,textview和imageview的Listview,其中包含一個arraylist

[英]Listview with checkbox, imageview, textview and imageview filled with an arraylist

我想創建一個listview來獲取arraylist中的數據。 這是單行的示例

在此輸入圖像描述

默認情況下禁用該復選框,它僅在longitemclicklistener中激活(用於多次刪除)。

最后一個圖像是一個菜單按鈕,用於打開刪除,共享等菜單列表。

我有一個帶有100個數字(字符串)的arraylist(myList),對於每個存儲的名稱,我想根據特定條件顯示/隱藏圖像

我有這一行:

row.xml

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="1">

    <CheckBox
        android:layout_width="45dp"
        android:layout_height="wrap_content"
        android:text=" "
        android:id="@+id/checkBox"
        android:checked="false" />

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/im_buho"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="                  TEXTVIEW"
        android:id="@+id/textView"
        android:layout_weight="0.66" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:src="@android:drawable/ic_menu_add"/>

</LinearLayout>

這是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" >

<ListView
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

我怎樣才能做到這一點?

我不知道怎么做我的慣例。 使用simplearrayadapter很容易,但我不能使用自定義行。 有幫助嗎? 吻,塔季揚娜。 對不起我的英文^^

以下是自定義適配器實現示例:

public class CustomUsersAdapter extends ArrayAdapter<User> {
    public CustomUsersAdapter(Context context, ArrayList<User> users) {
        super(context, 0, users);
     }

     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        User user = getItem(position);    
        // Check if an existing view is being reused, otherwise inflate the view
        if (convertView == null) {
           convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_user, parent, false);
        }
        // Lookup view for data population
        TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
        TextView tvHome = (TextView) convertView.findViewById(R.id.tvHometown);
        // Populate the data into the template view using the data object
        tvName.setText(user.name);
        tvHome.setText(user.hometown);
        // Return the completed view to render on screen
        return convertView;
    }
}

資源

您可以虛增您row.xml通過更換R.layout.item_userR.layout.row和更換User通過自己的POJO類

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM