带复选框的列表视图、图像视图、文本视图和图像视图,其中填充了数组列表
Listview with checkbox, imageview, textview and imageview filled with an arraylist
我想制作一个从数组列表中获取数据的列表视图。
这是单行的例子
默认情况下禁用该复选框,它仅在 longitemclicklistener(用于多次删除)中激活。
最后一张图片是一个菜单按钮,可打开用于删除、共享等的菜单列表。
我有一个包含 100 个数字(字符串)的数组列表(myList),对于每个存储的名称,我想 show/hide 根据特定条件
我有这一行:
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;
}
}
您可以通过将 R.layout.item_user
替换为 R.layout.row
来膨胀您的 row.xml
,并将 User
class 替换为您自己的 pojo
我想制作一个从数组列表中获取数据的列表视图。 这是单行的例子
默认情况下禁用该复选框,它仅在 longitemclicklistener(用于多次删除)中激活。
最后一张图片是一个菜单按钮,可打开用于删除、共享等的菜单列表。
我有一个包含 100 个数字(字符串)的数组列表(myList),对于每个存储的名称,我想 show/hide 根据特定条件
我有这一行:
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;
}
}
您可以通过将 R.layout.item_user
替换为 R.layout.row
来膨胀您的 row.xml
,并将 User
class 替换为您自己的 pojo