我想在我的应用程序中创建段落分隔符。 Firebase是我的后端。但是,Firebase不支持/ n单独的段落。因此,我从StackOverflow找到了一个解决方案,该解决方案放置了_b
而不是_n
,并且在检索时间后用_b
将此\n
替换了。但是,我不知道如何在我的代码中实现此方法。
这是我的文字部分
viewHolder.thrillersub_title.setText(model.getTitle());
这是我的MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ottamooli_sub);
Toolbar toolbar = findViewById(R.id.OttamooliSubtoolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Ottamooli");
if (getSupportActionBar()!=null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
MobileAds.initialize(this,APP_ID);
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
database = FirebaseDatabase.getInstance();
MCC = database.getReference("Ottamooli2");
recyclerView = (RecyclerView) findViewById(R.id.recycler_OttamooliSub);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager (layoutManager);
if (getIntent() != null)
categoryId = getIntent().getStringExtra("CategoryId");
if (!categoryId.isEmpty() && categoryId != null) {
loadListThrillerSubModel(categoryId);
}
}
private void loadListThrillerSubModel(String categoryId) {
adapter = new FirebaseRecyclerAdapter<OttamoolisubModel, OttamooliSubViewHolder>(OttamoolisubModel.class,
R.layout.ottamoolisub_items,
OttamooliSubViewHolder.class,
MCC.orderByChild("menuid").equalTo(categoryId)) {
@Override
protected void populateViewHolder(OttamooliSubViewHolder viewHolder, final OttamoolisubModel model, int position) {
viewHolder.thrillersub_title.setText(model.getTitle());
Picasso.get().load(model.getImage())
.into(viewHolder.thrillersub_image);
final OttamoolisubModel local = model;
viewHolder.setItemClickListner(new ItemClickListner() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
}
});
}
};
recyclerView.setAdapter(adapter);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==android.R.id.home)
finish();
return super.onOptionsItemSelected(item);
}
}
这是我的ViewHolder
public TextView thrillersub_title;
public ImageView thrillersub_image;
private ItemClickListner itemClickListner;
public void setItemClickListner(ItemClickListner itemClickListner) {
this.itemClickListner = itemClickListner;
}
public OttamooliSubViewHolder(View itemView) {
super(itemView);
thrillersub_title = (TextView)itemView.findViewById(R.id.thrillerSub_name);
thrillersub_image = (ImageView)itemView.findViewById(R.id.thrillerSub_image);
}
@Override
public void onClick(View v) {
itemClickListner.onClick(v,getAdapterPosition(),false);
}
这是我的模范
private String title, image, menuid, cyid;
public OttamoolisubModel() {
}
public OttamoolisubModel(String title, String image, String menuid, String cyid) {
this.title = title;
this.image = image;
this.menuid = menuid;
this.cyid = cyid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getMenuid() {
return menuid;
}
public void setMenuid(String menuid) {
this.menuid = menuid;
}
public String getCyid() {
return cyid;
}
public void setCyid(String cyid) {
this.cyid = cyid;
}
}
答案 0 :(得分:0)
在
setTitle(String title)
this.title = title.replace("_b","\n");
话虽如此,如果标题之外出现_b的话,可能会出现问题,您需要对其进行更好的解析。