Skip to content

Commit

Permalink
final commit on news API
Browse files Browse the repository at this point in the history
  • Loading branch information
Harounnn committed Mar 17, 2024
1 parent 06b1768 commit 8b96af0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/com/example/readitai/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
ArrayList<Model> models;

public Adapter(Context context, ArrayList<Model> models) {
this.models = models;
this.context = context;
}

@NonNull
Expand All @@ -37,14 +39,14 @@ public void onBindViewHolder(@NonNull Adapter.ViewHolder holder, int position) {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, sumNews.class);
intent.putExtra("content", models.get(position).getContent());
intent.putExtra("content", models.get(holder.getAdapterPosition()).getContent());
context.startActivity(intent);
}
});

holder.heading.setText(models.get(position).getTitle());
holder.description.setText(models.get(position).getContent());
Glide.with(context).load(models.get(position).getUrlToImage()).into(holder.image);
holder.heading.setText(models.get(holder.getAdapterPosition()).getTitle());
holder.description.setText(models.get(holder.getAdapterPosition()).getContent());
Glide.with(context).load(models.get(holder.getAdapterPosition()).getUrlToImage()).into(holder.image);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/example/readitai/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.readitai;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;

Expand All @@ -12,5 +13,10 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Fragment fragment = new MainFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment) // Replace with your container ID
.commit();
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>

<androidx.fragment.app.FragmentContainerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"
android:layout_below="@id/toolbar">
</androidx.fragment.app.FragmentContainerView>



</RelativeLayout>

0 comments on commit 8b96af0

Please sign in to comment.