显示更多文本的更好方法是什么?

时间:2018-12-15 14:29:35

标签: android android-intent textview settext

我正在为课程开发课堂笔记应用程序。在一项活动中,使用“回收者”视图显示课程名称:

Image 1

在另一个活动中,课程内容显示如下:

Image 2

为此,我正在使用intent putExtra-setText方法。 考虑到应用程序的内存,是否有更好的方法来流畅地显示更多文本,尤其是如果每堂课有50篇以上的文章和3-4页的文本内容。

ArticalDataModel.java

${CMAKE_CURRENT_SOURCE_DIR}

MainActivity.java

  private String artical_title,artical_desc;

    public ArticalDataModel(String artical_title, String artical_desc) {
        this.artical_title = artical_title;
        this.artical_desc = artical_desc;
    }

    public String getArtical_title() {
        return artical_title;
    }

    public void setArtical_title(String artical_title) {
        this.artical_title = artical_title;
    }

    public String getArtical_desc() {
        return artical_desc;
    }

    public void setArtical_desc(String artical_desc) {
        this.artical_desc = artical_desc;
    }
}

MyRvAdapter.java

public class MainActivity extends AppCompatActivity {
    List<ArticalDataModel> articalDataModels;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        articalDataModels = new ArrayList<>();


        articalDataModels.add(new ArticalDataModel("article one ",getResources().getString(R.string.a1)));
        articalDataModels.add(new ArticalDataModel("article two ",getResources().getString(R.string.a2)));
        articalDataModels.add(new ArticalDataModel("article three ",getResources().getString(R.string.a3)));
        articalDataModels.add(new ArticalDataModel("article four ",getResources().getString(R.string.a4)));
        articalDataModels.add(new ArticalDataModel("article five ",getResources().getString(R.string.a5)));
        articalDataModels.add(new ArticalDataModel("article six ",getResources().getString(R.string.a6)));
        articalDataModels.add(new ArticalDataModel("article seven ",getResources().getString(R.string.a7)));



        RecyclerView myrv = findViewById(R.id.recyclerviewid);
        MyRvAdapter myAdapter = new MyRvAdapter(this,articalDataModels);
        myrv.setLayoutManager(new LinearLayoutManager(this));
        myrv.setAdapter(myAdapter);

    }
}

DisplayArticle.java

public class MyRvAdapter extends RecyclerView.Adapter<MyRvAdapter.MyViewHolder> {
    private Context mContext;
    private List<ArticalDataModel> mData;
    public MyRvAdapter(Context mContext, List<ArticalDataModel> mData) {
        this.mContext = mContext;
        this.mData = mData; }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        View view;
        LayoutInflater mInflater = LayoutInflater.from(mContext);
        view  = mInflater.inflate(R.layout.artical_title_card, parent,false);
        return new MyViewHolder(view); }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int position) {
        myViewHolder.tv_art_title.setText(mData.get(position).getArtical_title());
        myViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext,DisplayArticle.class);
                intent.putExtra("Atitle",mData.get(position).getArtical_title());
                intent.putExtra("Atext",mData.get(position).getArtical_desc());
                mContext.startActivity(intent); }}); }

    @Override
    public int getItemCount() {
        return mData.size(); }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        TextView  tv_art_title;
        CardView cardView;

    public MyViewHolder(@NonNull View itemView){
        super(itemView);
        tv_art_title = itemView.findViewById(R.id.article_title_id);
        cardView = itemView.findViewById(R.id.cardviewid);
        }}

    @Override
    public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
        recyclerView.setAdapter(null);
        recyclerView.setLayoutManager(null);
        recyclerView.setOnClickListener(null);
        super.onDetachedFromRecyclerView(recyclerView);
    }}
  

只有7篇文章的演示应用程序占用80-90 mb(android   分析器)当我测试moto onepower(pie)时,是否有任何问题或   这是正常的吗,有人可以建议更好的方法吗,我是android新手   开发。

1 个答案:

答案 0 :(得分:0)

使用片段而不是开始新的活动。创建2个片段,一个保存您的课程名称,另一个保存您的课程内容。请记住,如果您只想显示一些使用片段,则活动是为了导航