Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview需要以标记的设置开始_Android_Listview - Fatal编程技术网

Android Listview需要以标记的设置开始

Android Listview需要以标记的设置开始,android,listview,Android,Listview,我试图找出这段代码,这样我就可以将每个listview项设置为已标记,因为现在它们以false开头,我需要单击它们来标记它们。但由于这是一个设置视图,它们应该按标记开始 private ListView settingListView; private String[] strListView; public View onCreateView(LayoutInflater inflater, final ViewGroup container,

我试图找出这段代码,这样我就可以将每个listview项设置为已标记,因为现在它们以false开头,我需要单击它们来标记它们。但由于这是一个设置视图,它们应该按标记开始

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设置ListView;
私有字符串[]strListView;
创建视图上的公共视图(布局、充气机、最终视图组容器、,
Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.fragment\u设置,容器,false);
settingListView=(ListView)rootView.findViewById(R.id.settingsListView);
strListView=getResources().getStringArray(R.array.settings\u列表);
ArrayAdapter objAdapter=新的ArrayAdapter(this.getActivity(),android.R.layout.simple\u list\u item\u multiple\u selection,strListView);
settingListView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
CheckedTextView CheckedTextView=((CheckedTextView)视图);
checkedTextView.setChecked(!checkedTextView.isChecked());
如果(位置==0){
CustomNotificationManager.setSound(checkedTextView.isChecked());
试一试{
CustomNotificationManager.makeSound(container.getContext());
}捕获(IOE异常){
e、 printStackTrace();
}
}
如果(位置==1){
CustomNotificationManager.setVibration(checkedTextView.isChecked());
CustomNotificationManager.vibrate(container.getContext());
}
如果(位置==2){
CustomNotificationManager.setPopUp(checkedTextView.isChecked());
CustomNotificationManager.makePopUp(container.getContext(),R.drawable.default_节点);
}
如果(位置==3){
CustomNotificationManager.setNotification(checkedTextView.isChecked());
CustomNotificationManager.MakeNotification(container.getContext(),R.drawable.default_节点);
}
如果(位置==4){
CustomNotificationManager.setQuietMode(checkedTextView.isChecked());
}
}
});
settingListView.setAdapter(objAdapter);
返回rootView;
}

如何设置要从一开始就标记的各行?

如果在展开布局后,只需为列表视图中的每个元素调用
setChecked
,会怎么样?大概是这样的:

for(int i = 0; i < settingsListView.getCount(); i++) {
    CheckedTextView view= ((CheckedTextView) settingsListView.getChildAt(i));
    view.setChecked(true);
}
for(int i=0;i
还是只想将特定项目设置为选中


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

对于设置视图,您可以使用SharedReferences,这样您就可以保存listView项的状态,并在创建视图时从SharedReferences加载此项。你可以得到更多的信息