gpt4 book ai didi

android - 列表项未在多选 ListView 中选中

转载 作者:行者123 更新时间:2023-11-29 01:45:09 25 4
gpt4 key购买 nike

我有以下设置:

Activity :

public class UploadActivity extends AbstractListActivity {

protected PackageAdapter mAdapter = new PackageAdapter();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
setListAdapter(mAdapter);
}
}

适配器:

public class PackageAdapter extends ArrayAdapter<PointPackage> {

...

@Override
public View getView(int position, View convertView, ViewGroup parent) {

TextView view;
if (convertView == null) {
view = (TextView) mInflater.inflate(R.layout.list_item_package, parent, false);
} else {
view = (TextView) convertView;
}

bind(getItem(position), view);

return view;
}

private void bind(PointPackage item, TextView view) {
view.setText(item.getName());
}
}

activity_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />

list_item_package.xml:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:drawableLeft="@drawable/collection"
android:drawablePadding="@dimen/compactPadding"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceListItem" />

我的问题是单击时未选择列表项...该行似乎是可单击的,单击时它会突出显示,但不会出现复选标记。我做错了什么?

编辑:这段代码很好。问题出在别处。

最佳答案

您需要实现 onItemClick 监听器,您可以在其中获取被单击的 View /项目。从该 View 获取 CheckedTextView 并将其标记为已选中。

关于android - 列表项未在多选 ListView 中选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21933962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com