gpt4 book ai didi

java - 如何获取自定义适配器中每个微调器的状态

转载 作者:太空宇宙 更新时间:2023-11-04 11:29:49 24 4
gpt4 key购买 nike

我有一个自定义适配器,可以在其中显示文本和微调器。我尝试存储每个微调器的状态,以便在 Activity 再次打开时显示相同的项目,我尝试了不同的操作,但没有成功。请问我该如何完成这个谢谢。这是我最近尝试过的事情

    CustomListAdapter(Context context, ArrayList<String> subjects) {
super(context, R.layout.custom_list_view, subjects);
}



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

LayoutInflater layoutInflater = LayoutInflater.from(getContext());
View customView = layoutInflater.inflate(R.layout.custom_list_view, parent, false);

singleSubject = getItem(position);


TextView singleText = (TextView) customView.findViewById(R.id.listSubjectsMyCourses);
colorLayout = (LinearLayout)customView.findViewById(R.id.colorForSubjects);
relativeLayout = (RelativeLayout)
customView.findViewById(R.id.relativeForView);
parentLayout = (RelativeLayout)
customView.findViewById(R.id.parentLayout);
points = new ArrayList<>();
selected = new ArrayList<>();
selectedsttring = new ArrayList<>();
customView.findViewById(R.id.textViewForGrades);
tinyDB = new TinyDB(getContext());



spinnerForGradePoints = (Spinner)customView.findViewById(R.id.spinnerForGrades);
final ArrayAdapter<String> gradePointAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_dropdown_item_1line, UserCourseSelection2.userSubjectGradePoint);
spinnerForGradePoints.setAdapter(gradePointAdapter);

spinnerForGradePoints.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
selectedItempos = adapterView.getSelectedItemPosition();
String getSelectedItem = adapterView.getItemAtPosition(i).toString();

tinyDB.putInt("selected", selectedItempos);


}



@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

singleText.setText(singleSubject);
colorLayout.setBackgroundColor(UserCourseSelection2.userSubjectsListColor.get(position));
int getSelected = tinyDB.getInt("selected");
spinnerForGradePoints.setSelection(getSelected);

return customView;

}

最佳答案

如果您不想使用像 dagger 这样的依赖注入(inject),那么 SharedPreferences 就是一种方法。或应用程序级别的某种自定义本地缓存。

对于微调器中的 SharedPreferences,请检查以下答案:

https://stackoverflow.com/a/13431729/5577679

关于java - 如何获取自定义适配器中每个微调器的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43918019/

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