Code to create news app in android studio

Here is a basic outline of the steps to create a news app in Android Studio:

Step 1: Create a new project in Android Studio

Step 2: Design the user interface

Step 3: Create a data model for the news articles

Step 4: Create a data source for the news articles

Step 5: Create an adapter to bind the data to the RecyclerView

Step 6: Set up the RecyclerView

Step 7: Implement navigation between articles

Step 8: Add functionality to the Button

Here is some sample code to get you started:

// NewsArticle.java
public class NewsArticle {
    private String title;
    private String summary;
    private String imageUrl;

    public NewsArticle(String title, String summary, String imageUrl) {
        this.title = title;
        this.summary = summary;
        this.imageUrl = imageUrl;
    }

    public String getTitle() {
        return title;
    }

    public String getSummary() {
        return summary;
    }

    public String getImageUrl() {
        return imageUrl;
    }
}

// NewsDataSource.java
public class NewsDataSource {
    private Retrofit retrofit;

    public NewsDataSource() {
        retrofit = new Retrofit.Builder()
               .baseUrl("https://api.example.com/")
               .addConverterFactory(GsonConverterFactory.create())
               .build();
    }

    public List<NewsArticle> getNewsArticles() {
        Call<List<NewsArticle>> call = retrofit.create(NewsApi.class).getNewsArticles();
        call.enqueue(new Callback<List<NewsArticle>>() {
            @Override
            public void onResponse(Call<List<NewsArticle>> call, Response<List<NewsArticle>> response) {
                List<NewsArticle> newsArticles = response.body();
                // Do something with the news articles
            }

            @Override
            public void onFailure(Call<List<NewsArticle>> call, Throwable t) {
                // Handle error
            }
        });
    }
}

// NewsAdapter.java
public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> {
    private List<NewsArticle> newsArticles;
    private Context context;

    public NewsAdapter(List<NewsArticle> newsArticles, Context context) {
        this.newsArticles = newsArticles;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.news_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        NewsArticle newsArticle = newsArticles.get(position);
        holder.titleTextView.setText(newsArticle.getTitle());
        holder.summaryTextView.setText(newsArticle.getSummary());
        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ArticleActivity.class);
                intent.putExtra("articleId", newsArticle.getId());
                context.startActivity(intent);
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView titleTextView;
        public TextView summaryTextView;
        public Button button;

        public ViewHolder(View itemView) {
            super(itemView);
            titleTextView = (TextView) itemView.findViewById(R.id.title_text_view);
            summaryTextView = (TextView) itemView.findViewById(R.id.summary_text_view);
            button = (Button) itemView.findViewById(R.id.button);
        }
    }
}

// MainActivity.java
public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private NewsAdapter newsAdapter;
    private List<NewsArticle> newsArticles;

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

        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        newsAdapter = new NewsAdapter(newsArticles, this);
        recyclerView.setAdapter(newsAdapter);

        NewsDataSource newsDataSource = new NewsDataSource();
        newsDataSource.getNewsArticles();
    }
}

This is just a basic outline, and you will need to customize and expand on this code to create a fully functional news app. You may also need to add additional features such as image loading, error handling, and user authentication.