Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
Java 如何保存CheckedTextView的文本_Java_Android - Fatal编程技术网

Java 如何保存CheckedTextView的文本

Java 如何保存CheckedTextView的文本,java,android,Java,Android,我在我的cardAdapter中使用checkedTextView并希望保存选中内容的文本。我看到了toast消息的用法,但没有看到如何保存它们(到共享首选项或数据库)。这可能吗?我是Android新手,请帮我 我已经为此编写了一个代码,但它不起作用,所以我问您“这可能吗?” 卡适配器 公共类CardAdapter扩展了RecyclerView.Adapter{ 私有上下文; 私人ArrayList词; 私人共享参考。编辑e; 私有ArrayList sharedP; 私有字符串字=null;

我在我的cardAdapter中使用checkedTextView并希望保存选中内容的文本。我看到了toast消息的用法,但没有看到如何保存它们(到共享首选项或数据库)。这可能吗?我是Android新手,请帮我

我已经为此编写了一个代码,但它不起作用,所以我问您“这可能吗?”

卡适配器

公共类CardAdapter扩展了RecyclerView.Adapter{ 私有上下文; 私人ArrayList词; 私人共享参考。编辑e; 私有ArrayList sharedP; 私有字符串字=null; 私有int id=0; 私有StringBuffer str=null; 私有布尔标志=true; 私人共享参考sp; 公共卡适配器(上下文mContext、ArrayList单词){ this.mContext=mContext; 这个单词=单词; } 公共类卡Tasarimtutucu扩展了RecyclerView.ViewHolder{ 私人信用卡; 私有CheckedTextView行文本; 公共卡TASARIMTUCU(@NonNull View itemView){ 超级(项目视图); this.rowCard=itemviewbyd(R.id.rowCard); this.rowText=itemviewbyd(R.id.rowText); } } @非空 @凌驾 公共卡TASARIMTUCU onCreateViewHolder(@NonNull ViewGroup parent,int viewType){ 视图v=LayoutInflater.from(parent.getContext()).flate(R.layout.card_design,parent,false); 退回新卡Tasarimtutucu(v); } @凌驾 BindViewHolder上的公共无效(@NonNull最终卡Tasarimtutucu holder,int位置){ sp=mContext.getSharedReferences(“选中”,Context.MODE\u PRIVATE); sharedP=newarraylist(); e=sp.edit(); word=words.get(position.getMean(); Log.e(“getMean”,单词); id=words.get(position.getId(); str=新的StringBuffer(“”); holder.rowText.setText(word); holder.rowText.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图v){ if(holder.rowText.isChecked()){ sharedP.remove(sharedP.indexOf(word)); flag=false; holder.rowText.setCheckMarkDrawable(空); holder.rowText.setChecked(false); }否则{ sharedP.add(word); flag=true; Log.e(“deneme”,word); holder.rowText.setCheckMarkDrawable(R.drawable.ic\u check\u black\u 24dp); holder.rowText.setChecked(true); } str.delete(0,str.length()); 对于(int i=0;i
和在共享首选项中保存val变量值如果您想在本地保存val

请共享使用的代码,以便社区可以查看您已经完成的工作,并在您遇到问题的领域为您提供帮助。但是,我们不是为您实现这些功能的you@Infamous我添加了我的代码,确保可以保存data从适配器到SharedReference或本地SQLite DB。由于我不知道我们正在保存的内容的性质,我真的无法帮助您使用什么选项。无论是SharedRefers还是DB。总之,将值保存为SP中的键对非常简单->
String val = checkedTextView.getText().toString()