java - How to get the data from .txt files in Android
问题描述
I am making an app where I have uploaded text files in Firebase Storage and now I want to retrieve those files and display the contents of those txt files in a text view inside a recycler view. I am able to get the uri of those text files but how do I display the contents of those files.
Here is the code I have done so far
public class RecyclerViewAdapter3 extends RecyclerView.Adapter<RecyclerViewAdapter3.ViewHolder> {
Context context3;
List<ImageUploadInfo> MainImageUploadInfoList;
public RecyclerViewAdapter3(Context context, List<ImageUploadInfo> TempList) {
this.MainImageUploadInfoList = TempList;
this.context3 = context;
}
public RecyclerViewAdapter3.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items3, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public int getItemCount() {
return MainImageUploadInfoList.size();
}
@Override
public void onBindViewHolder(final RecyclerViewAdapter3.ViewHolder holder, int position) {
ImageUploadInfo UploadInfo = MainImageUploadInfoList.get(position);
Uri uri = Uri.parse(UploadInfo.getImageURL());
Log.d("TAGGG" , ""+uri);
holder.userText.setText(uri.toString());
holder.imageNameTextView.setText(UploadInfo.getImageName());
}
class ViewHolder extends RecyclerView.ViewHolder {
public TextView imageNameTextView ;
public TextView userText;
public ViewHolder(View itemView) {
super(itemView);
userText = (TextView) itemView.findViewById(R.id.textView13);
imageNameTextView = (TextView) itemView.findViewById(R.id.caption);
}
}
}
In this code I am setting the uri in the textview. How do I set the content of the text file into the textview?
Please help
解决方案
将文件更改为 JSON 格式。
{
"data" : "your text here"
}
并使用通用方法下载数据和解析 json(我建议改造)。
推荐阅读
- php - 替换字符串中的值
- node.js - node:path 和 Math.floor 有问题
- mongodb - MongoDB v4 explain() 不返回扫描文档的数量(与以前的版本不同)。怎样成为?
- python - 将 keras (.h5) 模型转换为 tf 冻结图 (.pd) 格式后的精度损失
- java - 用户存在返回值不可读
- grails - 如何知道grails中上传的文件大小?
- node.js - TypeError:res.setHeader 不是函数,在启用 cors 时出现此错误
- python-3.x - 如何使用 python 返回所有嵌套对象?
- react-native - 反应原生 Android 构建错误 - react-native-square-in-app-payments
- java - 在java中创建自定义收集器