Commit 6446d3f4 authored by MUTTINENI NAVYA's avatar MUTTINENI NAVYA

added recycler view

parent 6f5876de
package com.example.instilostandfound;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.squareup.picasso.Picasso;
import java.util.List;
public class MyPostsAdaptor extends RecyclerView.Adapter<MyPostsAdaptor.myViewHolder> {
private Context mcontext;
private List<CreateFoundObject> mUploads;
public MyPostsAdaptor(Context context, List<CreateFoundObject> uploads){
mcontext = context;
mUploads=uploads;
}
@NonNull
@Override
public MyPostsAdaptor.myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mcontext).inflate(R.layout.list_item, parent, false);
return new myViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull MyPostsAdaptor.myViewHolder holder, int position) {
CreateFoundObject current_post = mUploads.get(position);
holder.textViewname.setText(current_post.getmTitle());
Picasso.with(mcontext).load(current_post.getImageUrl())
.fit()
.centerCrop()
.into(holder.imageView);
}
@Override
public int getItemCount() {
return mUploads.size();
}
public class myViewHolder extends RecyclerView.ViewHolder{
public TextView textViewname;
public ImageView imageView;
public myViewHolder(@NonNull View itemView) {
super(itemView);
textViewname = itemView.findViewById(R.id.list_item_textview);
imageView = itemView.findViewById(R.id.list_item_imageview);
}
}
}
package com.example.instilostandfound;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.ArrayList;
import java.util.List;
public class MyPosts_rv extends AppCompatActivity {
private RecyclerView mrecyclerView;
private MyPostsAdaptor myPostsAdaptor;
private DatabaseReference mDatabaseRef;
private List<CreateFoundObject> mPosts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_posts_rv);
mrecyclerView = findViewById(R.id.my_posts_rv);
mrecyclerView.setHasFixedSize(true);
mrecyclerView.setLayoutManager(new LinearLayoutManager(this));
mPosts = new ArrayList<>();
mDatabaseRef = FirebaseDatabase.getInstance().getReference("FoundItems");
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyPosts_rv">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/my_posts_rv"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
android:id="@+id/list_item_cardview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/list_item_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:textColor="@android:color/black"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"/>
<ImageView
android:id="@+id/list_item_imageview"
android:layout_width="match_parent"
android:layout_height="200dp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment