2017-07-21 74 views
-2

我是使用Firebase進行Android開發的新手。我被困在傳遞新的活動的意圖。我想在回收站視圖中點擊特定的卡片時,將url和url1傳遞給新的活動。如何將意圖傳遞給Firebase的新活動recyclerview

這裏是我的代碼

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

這裏是我的火力地堡數據庫 Database

+0

的可能的複製[Android的:使用意圖啓動任何活動(https://stackoverflow.com/questions/30959496/android-using-an-intent-to-start-any-activity) – DeKaNszn

回答

0

捆綁。

你在String中使用model.getUrl()並使用bundle來傳遞你想要的東西。

在你的onClick方法

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

,並在您的nextActivity

,你需要抓住你的包。

private void getIntentData() { 
    Bundle bundle = getIntent().getExtras(); 
    if (bundle != null) 
     Strin url = bundle.getString(key); 
} 
+0

如何在onClick中傳遞包裹 –

+0

您的onClick方法在哪裏? – nikeru8

+0

itemView.setOnClickListener(新View.OnClickListener(){ @Override 公共無效的onClick(查看視圖){ 意圖意圖=新意圖(view.getContext(),projectView.class); 視圖.getContext()。startActivity(intent); } }); } 在意圖我想傳遞intent.putExtra(PROJECT_URL,project.getUrl());這 –

相關問題