[英]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_user
与R.layout.row
和更换User
通过自己的POJO类
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.