0

I'm new android developper. In my application I have a main activity with toolbar, that contains a title, and a recycler view.

The recycler view contains some items. I want to open a activity on click on them. My code is able to open the activity but the toolbar disappear.

I open the activity like this:

public VHolder(final View itemView){
        super(itemView);

        title = ((TextView) itemView.findViewById(R.id.articleTitle));

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(itemView.getContext(), ArticleActivity.class);
                intent.putExtra("title", currentNews.title);
                intent.putExtra("content", currentNews.htmlContent);
                itemView.getContext().startActivity(intent);
            }
        });
    }

Have you any ideas and advices ?

Sorry about my poor english ;).

Antrax
  • 13
  • 1
  • 6

2 Answers2

3

You are doing everything in the correct way. The problem is that toolbar is just another widget on your Activity and cannot be shared between multiple activities. So you should add toolbar view to the layout of the Activity which you are starting (ArticleActivity).

As another option you can show Fragment over RecyclerView instead of starting new Activity. Similar to this: how to open a different fragment on recyclerview OnClick

Community
  • 1
  • 1
amukhachov
  • 5,822
  • 1
  • 41
  • 60
  • Sorry, I have forgotten a detail. In design mode, I see the toolbar in the opened activity (ArticleActivity). It define into the theme of the application. – Antrax Jun 01 '16 at 09:19
0

I have found the cause of my problem of toolbar. The opened activity (ArticleActivity) not extends "AppCompatActivity" like the main activity but, "Activity".

Antrax
  • 13
  • 1
  • 6