简体   繁体   English

带有复选框,imageview,textview和imageview的Listview,其中包含一个arraylist

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

I want to make a listview that takes the data from an arraylist. 我想创建一个listview来获取arraylist中的数据。 This is an example of the single row 这是单行的示例

在此输入图像描述

The checkbox is disabled by default, it only gets activates in a longitemclicklistener(for multiple delete). 默认情况下禁用该复选框,它仅在longitemclicklistener中激活(用于多次删除)。

The last image is a menu button that opens a menu list for delete, share, etc. 最后一个图像是一个菜单按钮,用于打开删除,共享等菜单列表。

I have an arraylist(myList) with 100 numbers(Strings), For each stored name, I want to show/hide the image according to certain condition 我有一个带有100个数字(字符串)的arraylist(myList),对于每个存储的名称,我想根据特定条件显示/隐藏图像

I have this row: 我有这一行:

row.xml 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>

This is the activity_main.xml 这是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>

How can I do that? 我怎样才能做到这一点?

I don´t know how make my customadapter. 我不知道怎么做我的惯例。 With a simplearrayadapter is easy but I can´t use a custom row. 使用simplearrayadapter很容易,但我不能使用自定义行。 Any help? 有帮助吗? Kisses, Tatyana. 吻,塔季扬娜。 Sorry for my English ^^ 对不起我的英文^^

Here is a sample custom adapter implementation: 以下是自定义适配器实现示例:

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;
    }
}

Source 资源

You can inflate your row.xml by replacing R.layout.item_user with R.layout.row and replace the User class by your own pojo 您可以虚增您row.xml通过更换R.layout.item_userR.layout.row和更换User通过自己的POJO类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM