【问题标题】:How to get the data from .txt files in Android如何从 Android 中的 .txt 文件中获取数据
【发布时间】:2019-07-10 09:15:08
【问题描述】:

我正在制作一个应用程序,我在 Firebase Storage 中上传了文本文件,现在我想检索这些文件并在回收站视图内的文本视图中显示这些 txt 文件的内容。我能够获取这些文本文件的 uri,但是如何显示这些文件的内容。

这是我到目前为止所做的代码

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);
    }
}
}

在这段代码中,我在 textview 中设置 uri。如何将文本文件的内容设置到 textview 中?

请帮忙

【问题讨论】:

  • 为什么要使用文件系统将数据保存在 Firebase 存储中?您可以使用 firebase 数据库或 firestore 来执行此操作。

标签: java android firebase firebase-storage


【解决方案1】:

将您的文件更改为 JSON 格式。

{
     "data" : "your text here"
}

并使用通用方法下载数据和解析json(我建议Retrofit)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    相关资源
    最近更新 更多