gpt4 book ai didi

android - Listview需要开始标记设置

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

我正在尝试找出这段代码,以便我可以将每个 ListView 项目设置为标记,因为现在它们以假开始,我需要单击它们来标记它们中的每一个。但由于这是一个设置 View ,因此它们应该以标记的方式开始。

private ListView settingListView;
private String[] strListView;

public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
settingListView = (ListView) rootView.findViewById(R.id.settingsListView);
strListView = getResources().getStringArray(R.array.settings_list);
ArrayAdapter<String> objAdapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_multiple_choice, strListView);



settingListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckedTextView checkedTextView = ((CheckedTextView) view);
checkedTextView.setChecked(!checkedTextView.isChecked());


if (position == 0) {
CustomNotificationManager.setSound(checkedTextView.isChecked());
try {
CustomNotificationManager.makeSound(container.getContext());
} catch (IOException e) {
e.printStackTrace();
}
}

if (position == 1) {
CustomNotificationManager.setVibration(checkedTextView.isChecked());
CustomNotificationManager.vibrate(container.getContext());
}

if (position == 2) {
CustomNotificationManager.setPopUp(checkedTextView.isChecked());
CustomNotificationManager.makePopUp(container.getContext(), R.drawable.default_node);
}

if (position == 3) {
CustomNotificationManager.setNotification(checkedTextView.isChecked());
CustomNotificationManager.makeNotficiation(container.getContext(), R.drawable.default_node);
}

if (position == 4) {

CustomNotificationManager.setQuietMode(checkedTextView.isChecked());
}

}
});


settingListView.setAdapter(objAdapter);

return rootView;
}

如何设置要从头开始标记的各个行?

最佳答案

如果您在展开布局后为 ListView 中的每个元素调用 setChecked 会怎么样?像这样:

for(int i = 0; i < settingsListView.getCount(); i++) {
CheckedTextView view= ((CheckedTextView) settingsListView.getChildAt(i));
view.setChecked(true);
}

或者您只想将特定项目设置为已选中?

但通常对于设置,您应该使用现有的 PreferenceActivity 或 PreferenceFragment 类并访问 SharedPreferences 中的值。

关于android - Listview需要开始标记设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33330190/

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