我是使用Firebase进行Android开发的新手。我不愿意将意图传递给新活动。我想在回收站视图中点击特定卡片时将url和url1传递给新活动。
这是我的代码
MainActivity
myRef = FirebaseDatabase.getInstance().getReference("project").child("electronics");
recyclerView = (RecyclerView) findViewById(R.id.recycle);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
FirebaseRecyclerAdapter<Project,BlogViewHolder> adapter = new FirebaseRecyclerAdapter<Project, BlogViewHolder>(
Project.class,
R.layout.card,
BlogViewHolder.class,
myRef
) {
@Override
protected void populateViewHolder(BlogViewHolder viewHolder, Project model, int position) {
viewHolder.setProjectName(model.getProjectName());
viewHolder.setUrl1(model.getUrl1());
progressDialog.hide();
}
};
recyclerView.setAdapter(adapter);
}
public static class BlogViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView project1;
ImageView imageview;
public BlogViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
project1 = itemView.findViewById(R.id.textView);
imageview = itemView.findViewById(R.id.projectImage);
}
public void setProjectName(String projectName) {
project1.setText(projectName);
}
public void setUrl1(String url1) {
Picasso.with(itemView.getContext())
.load(url1)
.into(imageview);
}
Project.java
public class Project {
private String projectName,url,url1;
public Project() {
}
public Project(String projectName, String url, String url1) {
this.projectName = projectName;
this.url = url;
this.url1 = url1;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl1() {
return url1;
}
public void setUrl1(String url1) {
this.url1 = url1;
}}
这是我的Firebase数据库 Database
答案 0 :(得分:0)
包。
你在String中得到model.getUrl()并使用bundle来传递你想要的东西。
Triangle result = new Triangle(10,10,10);
并在你的nextActivity中,你需要抓住你的捆绑包。
@Override
public void onClick(View v) {
switch (v.getId()) {
case xxxx:
Intent intent = new Intent(mActivity, nextActivity.class);
Bundle bundle = new Bundle();
String value = model.getUrl();
bundle.putString(key, value);
intent.putExtras(bundle);
startActivity(intent);
break;
}
}