I fetch data from database and put it to RecyclerView. My database arrives 4 items I see it with log debug then I send it to my adapter. However I see only first item on my screen.
my adapter ListArticleAdapter
package uz.sherdevs.alishernavoiy.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import uz.sherdevs.alishernavoiy.R;
import uz.sherdevs.alishernavoiy.model.Article;
public class ListArticleAdapter extends RecyclerView.Adapter<ListArticleAdapter.MyViewHolder> {
private Context context;
private List<Article> articleList;
public ListArticleAdapter(Context context, List<Article> articleList) {
this.context = context;
this.articleList = articleList;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.item_list, parent, false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
holder.tv_title.setText(articleList.get(position).getTitle());
}
#Override
public int getItemCount() {
// Log.d("list", "" + articleList.size());
return articleList.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
TextView tv_title;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
tv_title = itemView.findViewById(R.id.article_title);
}
}
}
MainActivity
package uz.sherdevs.alishernavoiy;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.util.Log;
import java.util.List;
import uz.sherdevs.alishernavoiy.adapter.ListArticleAdapter;
import uz.sherdevs.alishernavoiy.database.SQLiteDBHelper;
import uz.sherdevs.alishernavoiy.model.Article;
public class MainActivity extends AppCompatActivity {
private RecyclerView articleRecyclerView;
private ListArticleAdapter adapter;
private List<Article> articleList;
private SQLiteDBHelper dbHelper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
articleRecyclerView = (RecyclerView)findViewById(R.id.articles_recyclerview);
dbHelper = new SQLiteDBHelper(this);
articleList = dbHelper.getArticles();
// for (Article article : articleList) {
// Log.d("list", article.getTitle());
// }
articleRecyclerView.setHasFixedSize(true);
adapter = new ListArticleAdapter(this, articleList);
// Log.d("list", articleList.toString());
articleRecyclerView.setAdapter(adapter);
articleRecyclerView.setLayoutManager(new LinearLayoutManager(this));
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity"
android:background="#drawable/background_icon"
>
<ImageView
android:src="#drawable/background_regtangle_green"
android:scaleType="centerCrop"
android:id="#+id/circle_background"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.3"
app:layout_constraintWidth_percent="1"
app:layout_constraintVertical_bias="0"
/>
<TextView
android:text="Dostonlar"
android:textColor="#FFDF6A"
android:textSize="60sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#id/circle_background"
app:layout_constraintLeft_toLeftOf="#id/circle_background"
app:layout_constraintRight_toRightOf="#id/circle_background"
app:layout_constraintBottom_toBottomOf="#id/circle_background"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintVertical_bias="0.3"
android:fontFamily="#font/myfont"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/articles_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="?attr/actionBarSize">
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>
item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp">
<androidx.cardview.widget.CardView
android:id="#+id/cardview1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.15"
app:layout_constraintWidth_percent="0.8"
app:cardCornerRadius="20dp"
app:layout_constraintVertical_bias="0.23"
app:cardElevation="20dp"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/article_title"
android:textSize="45sp"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.6"
android:gravity="center"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
I got 4 Objects from my database with command
articleList = dbHelper.getArticles();
However I see only first one on the screen.
Moreover as you see I loged in my adapter
#Override
public int getItemCount() {
// Log.d("list", "" + articleList.size());
return articleList.size();
}
That size also shows 4.
In item_list.xml, change android:layout_height="match_parent" with android:layout_height="wrap_content"
Related
I'm trying to show all the card views using recycler view in main activity. Although I did not set a huge margin between card views, my recycler view shows a huge space to print the next card view. please see my attached image, you'll understand what I'm trying to say. I've attached all the code here. Can you please advise how to solve this problem? Thank you.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:listitem="#layout/note_card" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="50dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="#+id/recyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/add" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="7dp"
app:cardBackgroundColor="#color/green"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textViewTitleCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="20sp" />
<TextView
android:id="#+id/textViewDescriptionCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginTop="16dp"
android:text="TextView"
android:textSize="16sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
package com.destructivepaul.quicknote;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.NoteHolder>{
private List<MyNote> myNoteList = new ArrayList<>();
// private Context context;
public void setMyNoteList(List<MyNote> myNoteList) {
this.myNoteList = myNoteList;
notifyDataSetChanged();
Log.i("info","note updated on adapter. note list size: "+myNoteList.size());
}
//public void setContext(Context context) {
// this.context = context;
// notifyDataSetChanged();
// Log.i("info","context updated on adapter");
// }
#NonNull
#Override
public NoteHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.note_card
,parent,false);
return new NoteHolder(view);
}
#Override
public void onBindViewHolder(#NonNull NoteHolder holder, int position) {
MyNote myNote=myNoteList.get(position);
holder.textViewTitle.setText(myNote.getNote_title());
holder.textViewDescription.setText(myNote.getNote_description());
}
#Override
public int getItemCount() {
return myNoteList.size();
}
public class NoteHolder extends RecyclerView.ViewHolder{
private TextView textViewTitle, textViewDescription;
private CardView cardView;
public NoteHolder(#NonNull View itemView) {
super(itemView);
textViewTitle=itemView.findViewById(R.id.textViewTitleCard);
textViewDescription=itemView.findViewById(R.id.textViewDescriptionCard);
cardView=itemView.findViewById(R.id.cardView);
Log.i("info","card design found on adapter");
}
}
}
package com.destructivepaul.quicknote;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private FloatingActionButton fab;
private RecyclerView recyclerView;
private MyNoteViewModel myNoteViewModel;
private ActivityResultLauncher<Intent> activityResultLauncherForAddNote;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//resisterActivity
resisterActivityForAddNote();
fab=findViewById(R.id.fab);
recyclerView=findViewById(R.id.recyclerView);
NoteAdapter adapter=new NoteAdapter();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
Log.i("info","set the adapter");
myNoteViewModel = new ViewModelProvider.AndroidViewModelFactory(getApplication())
.create(MyNoteViewModel.class);
myNoteViewModel.getAllNotes().observe(MainActivity.this, new Observer<List<MyNote>>() {
#Override
public void onChanged(List<MyNote> myNotes) {
adapter.setMyNoteList(myNotes);
Log.i("info","adapter is called to update data");
}
});
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent =new Intent(MainActivity.this,CreateNoteActivity.class);
//resister activity launcher
activityResultLauncherForAddNote.launch(intent);
Log.i("info","called resister activity launcher on fab");
}
});
}
public void resisterActivityForAddNote(){
activityResultLauncherForAddNote=registerForActivityResult(new ActivityResultContracts.StartActivityForResult()
, new ActivityResultCallback<ActivityResult>() {
#Override
public void onActivityResult(ActivityResult result) {
int resultCode=result.getResultCode();
Intent data = result.getData();
if (resultCode==RESULT_OK && data !=null) {
String title = data.getStringExtra("title");
String description = data.getStringExtra("description");
String colorName = data.getStringExtra("color");
MyNote myNote = new MyNote(title, description, colorName);
Log.i("info", "new note created on activity result");
myNoteViewModel.insert(myNote);
Log.i("info", "note saved to database");
}
}
});
}
}
I've solved my problem by myself. The problem was on card layout design(parent layout height should be wrap content instead of match parent).
fragment_leaderboard.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LeaderboardsFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
row_leaderboard.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"?
android:layout_height="wrap_content"
android:background="#color/cream">
<TextView
android:id="#+id/index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:fontFamily="#font/gotham_bold"
android:text="#1"
android:textColor="#color/brown"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="#+id/imageView7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/imageView7" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/index"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/menu_profile2" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:fontFamily="#font/gotham_bold"
android:text="Name of Winner"
android:textColor="#color/brown"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="#+id/imageView7"
app:layout_constraintStart_toEndOf="#+id/imageView7"
app:layout_constraintTop_toTopOf="#+id/imageView7" />
<TextView
android:id="#+id/coins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:fontFamily="#font/gotham_bold"
android:text="1230"
android:textColor="#color/brown"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="#+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/name" />
</android.constraintlayout.widget.ConstraintLayout>
LeaderBoardAdapter.java
package com.android.myquiz;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.android.myquiz.databinding.RowLeaderboardBinding;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
public class LeaderBoardAdapter extends
RecyclerView.Adapter<LeaderBoardAdapter.LeaderboardViewHolder> {
Context context;
ArrayList<User> users;
public LeaderBoardAdapter(Context context, ArrayList<User> users){
this.context = context;
this.users = users;
}
#NonNull
#NotNull
#Override
public LeaderboardViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(context).inflate(R.layout.row_leaderboard, parent,
false);
return new LeaderboardViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull LeaderboardViewHolder holder, int position) {
User user = users.get(position);
holder.binding.name.setText(user.getName1());
holder.binding.coins.setText(String.valueOf(user.getCoins()));
holder.binding.index.setText(String.format("#%d", position+1));
}
#Override
public int getItemCount() {
return users.size();
}
public class LeaderboardViewHolder extends RecyclerView.ViewHolder {
TextView id;
RowLeaderboardBinding binding;
public LeaderboardViewHolder(#NonNull View itemView) {
super(itemView);
binding = RowLeaderboardBinding.bind(itemView);
}
}
}
LeaderboardFragments.java
package com.android.myquiz;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.myquiz.databinding.FragmentLeaderboardsBinding;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QuerySnapshot;
import org.w3c.dom.Document;
import java.util.ArrayList;
public class LeaderboardsFragment extends Fragment {
public LeaderboardsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
FragmentLeaderboardsBinding binding;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
// Inflate the layout for this fragment
binding = FragmentLeaderboardsBinding.inflate(inflater, container,false);
FirebaseFirestore database = FirebaseFirestore.getInstance();
final ArrayList<User> users = new ArrayList<>();
final LeaderBoardAdapter adapter = new LeaderBoardAdapter(getContext(), users);
binding.recyclerView.setAdapter(adapter);
binding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
database.collection("users")
.orderBy("coins", Query.Direction.DESCENDING).get().addOnSuccessListener(new
OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (DocumentSnapshot snapshot : queryDocumentSnapshots){
User user = snapshot.toObject(User.class);
users.add(user);
}
adapter.notifyDataSetChanged();
}
});
return binding.getRoot();
}
}
this is my code I want to retrieve data from the firebase real-time database in recyclerView in fragments.
Okay, so looks like you are able to fetch the data from firebase, but are making a mistake in setting the data.
When you are calling adapter.notifyDataSetChanged(), you need to take care that you are passing the new users list, to the adapter.
You need to create a method inside your adapter class,
public void setUsersList(ArrayList<User> users) {
this.users = users;
notifyDatasetChanged();
}
and call it inside your fragment like, adapter.setUsersList(users), instead of calling adapter.notifyDataSetChanged().
My rows are not in the same size for some reason.I tried everything but it didn't work.By the way I'm very new to android.
I tried changing my row.xml but it did not work:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="3dp"
app:cardElevation="3dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_gravity="top">
<ImageView
android:id="#+id/imageIv"
android:layout_width="35dp"
android:layout_height="34dp"
android:background="#drawable/circulo_azul"
android:src="#drawable/transferenciablue" />
<TextView
android:id="#+id/titleTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_toEndOf="#id/imageIv"
android:layout_toRightOf="#id/imageIv"
android:text="Title"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
This is the activitymain.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation = "vertical"
tools:context=".MainActivity"
>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:id="#+id/recyclerView"/>
</LinearLayout>
MyAdapter.java with onBindViewHolder:
package com.example.demoapp;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import android.content.Context;
public class MyAdapter extends RecyclerView.Adapter<MyHolder> {
Context c;
ArrayList<Model> models; // this array list creates a list of arrays which parameters define in my model class
public MyAdapter(Context c, ArrayList<Model> models) {
this.c = c;
this.models = models;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row,null); // this line inflate my row
return new MyHolder(view); // this will return my view to holder class
}
#Override
public void onBindViewHolder(#NonNull MyHolder myHolder, int i) {
myHolder.mTitle.setText(models.get(i).getTitle()); // here i is position
myHolder.mImaeView.setImageResource(models.get(i).getImg());
}
#Override
public int getItemCount() {
return models.size();
}
}
MyHolder class:
package com.example.demoapp;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class MyHolder extends RecyclerView.ViewHolder {
ImageView mImaeView;
TextView mTitle;
public MyHolder(#NonNull View itemView) {
super(itemView);
this.mImaeView = itemView.findViewById(R.id.imageIv);
this.mTitle = itemView.findViewById(R.id.titleTv);
}
}
What do I need to change to make them appear proportional?Thanks
make sure that you will write this type of code in BindViewHolder:
#Override
public folder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.your_layout_name,parent,false);
return new viewHolderClass(view);
}
some time width cannot appear properly because viewGroup cannot use
Change android:layout_gravity="top" to android:layout_gravity="center"
So I am trying to use a custom layout for my notepad part of my app, but I just can't seem to be able to make it appear, below I'll display the notepad activity itself, the layout file and the adapter class that I made to inflate it in the hopes that I can get help to solve it.
The Notepad Activity:
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class Notepad extends AppCompatActivity {
Adapter adapter;
List<Note> notes;
RecyclerView recyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notepad);
Toolbar toolbar2 = findViewById(R.id.toolbar2);
setSupportActionBar(toolbar2);
DataBaseHelper db = new DataBaseHelper(this);
notes = db.getNotes();
recyclerView = findViewById(R.id.listOfnotes);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new Adapter(this, notes);
recyclerView.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.add_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
if(item.getItemId() == R.id.add){
startActivity(new Intent(this, AddNote.class));
}
return super.onOptionsItemSelected(item);
}
}
The layout file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:background="#FAFAFA"
android:padding="5dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardElevation="0dp"
app:contentPadding="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="5dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="83dp"
android:layout_height="61dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/constraintLayout"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/nTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="Sample Note Title"
android:textAlignment="viewStart"
android:textAllCaps="false"
android:textColor="#android:color/background_dark"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/nDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="created : 7/31/2019"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/nTitle" />
<TextView
android:id="#+id/nTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="08:02"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/nDate"
app:layout_constraintTop_toBottomOf="#+id/nTitle" />
<TextView
android:id="#+id/listId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:text="TextView"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/nTitle"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
The adapter class:
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
LayoutInflater inflater;
List<Note> notes;
Adapter(Context context, List<Note> notes){
this.inflater = LayoutInflater.from(context);
this.notes = notes;
}
#NonNull
#Override
public Adapter.ViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int viewType) {
View view = inflater.inflate(R.layout.custom_list_view, viewGroup, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull Adapter.ViewHolder viewHolder, int i) {
String title = notes.get(i).getTitle();
String date = notes.get(i).getDate();
String time = notes.get(i).getTime();
Log.d("Title", "onBindViewHolder: Title -> " + title);
viewHolder.nTitle.setText(title);
viewHolder.nDate.setText(date);
viewHolder.nTime.setText(time);
}
#Override
public int getItemCount() {
return notes.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder{
TextView nTitle, nDate, nTime;
public ViewHolder(#NonNull View itemView) {
super(itemView);
nTitle = itemView.findViewById(R.id.nTitle);
nDate = itemView.findViewById(R.id.nDate);
nTime = itemView.findViewById(R.id.nTime);
}
}
}
Notepad Activity layout file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Notepad">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#color/colorPrimary" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listOfnotes"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#cd0190"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar2"
app:layout_constraintVertical_bias="0.0" />
</androidx.appcompat.widget.LinearLayoutCompat>
I am completely beginner to android so there might be some studpidness in my case.
I am trying to make an Instagram clone app. But I am stuck in displaying users feed. I am fetching my data from Parse Server Then its stored in Two ArrayList 1 stores all Bitmaps and other all strings. Through my log i can see that my data is fetching properly but it is not displayed any where on the activity.
I am providing the activity code and all the necessary information any help would be greatly appreciated.
userTimeLine.class :
package com.example.avail.instagramclone;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.parse.FindCallback;
import com.parse.GetDataCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import java.util.ArrayList;
import java.util.List;
public class userTimeLine extends AppCompatActivity {
TextView userName;
String currLoggedInUser;
ArrayList<String> postsByUser;
ArrayList<Bitmap> imagesByUser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_time_line);
postsByUser = new ArrayList<String>();
imagesByUser = new ArrayList<Bitmap>();
String selectedUser = getIntent().getStringExtra("SelectedUser");
Log.i("Selected User Is " ,selectedUser);
userName = findViewById(R.id.username);
userName.setText(selectedUser.toUpperCase());
final RecyclerView recyclerView = findViewById(R.id.recView);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
final RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(postsByUser,imagesByUser);
recyclerView.setAdapter(recyclerViewAdapter);
ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
query.whereEqualTo("username",selectedUser);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e==null){
Log.i("Loading Posts","True");
Log.i("No Of Posts", String.valueOf(objects.size()));
if (objects.size()>0){
for(ParseObject object : objects){
ParseFile file = (ParseFile) object.get("image");
file.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if(e==null){
Bitmap bitmapImage = BitmapFactory.decodeByteArray(data, 0, data.length);
imagesByUser.add(bitmapImage);
Log.i("Status","Bitmap Fetched!");
Log.i("Content In Images", String.valueOf(imagesByUser.size()));
recyclerViewAdapter.notifyDataSetChanged();
}
else{
Log.i("info", e.getMessage());
}
}
});
String status = (String) object.get("poststatus");
postsByUser.add(status);
}
Log.i("Content In Status", String.valueOf(postsByUser.size()));
Log.i("Content In Images", String.valueOf(imagesByUser.size()));
}else {
Toast.makeText(getApplicationContext(),"NO POSTS BY USER",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(getApplicationContext(),"NETWORK ERROR!",Toast.LENGTH_SHORT).show();
Log.i("Network Error ",e.getMessage());
}
}
});
}
}
Adapter Class for the recycler view named as: RecyclerViewAdapter :
**
package com.example.avail.instagramclone;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private ArrayList<String> postStatuses ;
private ArrayList<Bitmap> postImages;
ImageView postImage;
TextView postStatus;
public RecyclerViewAdapter(ArrayList<String> postStatuses, ArrayList<Bitmap> postImages){
this.postStatuses = postStatuses;
this.postImages = postImages;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View customViewForDisplayingFeed = inflater.inflate(R.layout.recycler_list_users_feed,parent,false);
return new ViewHolder(customViewForDisplayingFeed);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
String status = postStatuses.get(position);
Bitmap image = postImages.get(position);
postImage.setImageBitmap(image);
postStatus.setText(status);
}
#Override
public int getItemCount() {
return postStatuses.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public ViewHolder(View itemView) {
super(itemView);
postImage = itemView.findViewById(R.id.userFeedImageListItem);
postStatus = itemView.findViewById(R.id.userFeedPostListItem);
}
}
}
**
Layout file for RecyclerView item named as recycler_list_users_feed.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/userFeedImageListItem"
android:layout_width="match_parent"
android:layout_height="261dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/logo" />
<TextView
android:id="#+id/userFeedPostListItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Here comes the post status"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userFeedImageListItem" />
</LinearLayout>
Also, my activity file named as activity_user_time_line.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".userTimeLine">
<android.support.v7.widget.RecyclerView
android:id="#+id/recView"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/view4"
app:layout_constraintStart_toEndOf="#+id/view4"
app:layout_constraintTop_toBottomOf="#+id/username" />
<View
android:id="#+id/view4"
style="#style/Divider"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray"
app:layout_constraintBottom_toTopOf="#+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/usersList" />
<View
android:id="#+id/view3"
style="#style/Divider"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:background="#f0f1f1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view3"
app:srcCompat="#drawable/usericon" />
<TextView
android:id="#+id/TIMELINE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="TIMELINE"
android:textColor="#android:color/black"
app:layout_constraintBottom_toBottomOf="#+id/view3"
app:layout_constraintEnd_toStartOf="#+id/view3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/view3"
app:layout_constraintTop_toTopOf="#+id/view3" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="USERNAME"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#+id/view4"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/view4"
app:layout_constraintTop_toBottomOf="#+id/imageView3" />
</android.support.constraint.ConstraintLayout>
Last but not the least my log cat :).
NOTE : MY APP ISN'T CRASHING BTW.
09-15 03:35:31.559 21397-21397/com.example.avail.instagramclone I/Selected User Is: abuzar
09-15 03:35:31.583 21397-21726/com.example.avail.instagramclone I/QCNEA : |NIMS|: getaddrinfo: hostname 18.222.87.194 servname NULL numeric 4 appname /system/bin/app_process
09-15 03:35:31.586 21397-21726/com.example.avail.instagramclone I/QCNEA : |NIMS|: getaddrinfo: hostname 18.222.87.194 servname NULL numeric 4 appname /system/bin/app_process
09-15 03:35:32.065 21397-21397/com.example.avail.instagramclone I/Loading Posts: True
09-15 03:35:32.065 21397-21397/com.example.avail.instagramclone I/No Of Posts: 1
09-15 03:35:32.070 21397-21397/com.example.avail.instagramclone I/Content In Status: 1
09-15 03:35:32.070 21397-21397/com.example.avail.instagramclone I/Content In Images: 0
09-15 03:35:32.110 21397-21731/com.example.avail.instagramclone D/dalvikvm: GC_FOR_ALLOC freed 568K, 13% free 26178K/30084K, paused 14ms, total 14ms
09-15 03:35:32.130 21397-21397/com.example.avail.instagramclone D/dalvikvm: GC_FOR_ALLOC freed 1531K, 13% free 26212K/30084K, paused 14ms, total 14ms
09-15 03:35:32.177 21397-21397/com.example.avail.instagramclone I/dalvikvm-heap: Grow heap (frag case) to 43.627MB for 16777232-byte allocation
09-15 03:35:32.298 21397-21397/com.example.avail.instagramclone I/Status: Bitmap Fetched!
09-15 03:35:32.298 21397-21397/com.example.avail.instagramclone I/Content In Images: 1
I think what you have wrong is postImage and postStatus in the Adapter.
postImage and postStatus should be attributes of the ViewHolder class.
You would initialize them after inflating the ViewHolder's layout. And give them the value to display in onBindViewholder().
A side note: Keeping an ArrayList of Bitmap is perhaps not a good idea because they can fill up your available memory.
Perhaps it is better to cache the Bitmas in some folder and keep an ArrayList of the paths.
And then read them from that folder when you need to display them.
maybe your problem happened in your Adapter's ViewHolder.
you can exchange your Adapter code like this and then try to compile your app again.
package com.example.avail.instagramclone;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class RecyclerViewAdapter extends
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private ArrayList<String> postStatuses ;
private ArrayList<Bitmap> postImages;
public RecyclerViewAdapter(ArrayList<String> postStatuses, ArrayList<Bitmap> postImages){
this.postStatuses = postStatuses;
this.postImages = postImages;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View customViewForDisplayingFeed = inflater.inflate(R.layout.recycler_list_users_feed,parent,false);
return new ViewHolder(customViewForDisplayingFeed);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
String status = postStatuses.get(position);
Bitmap image = postImages.get(position);
viewHolder.postImage.setImageBitmap(image);
viewHolder.postStatus.setText(status);
}
#Override
public int getItemCount() {
return postStatuses.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
ImageView postImage;
TextView postStatus;
public ViewHolder(View itemView) {
super(itemView);
postImage = itemView.findViewById(R.id.userFeedImageListItem);
postStatus = itemView.findViewById(R.id.userFeedPostListItem);
}
}
}
Let's try another thing:
We change your RecyclerViewAdapter with this
import java.util.ArrayList;
public class RecyclerViewAdapter extends
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private ArrayList<String> postStatuses ;
private ArrayList<Bitmap> postImages;
public RecyclerViewAdapter(ArrayList<String> postStatuses, ArrayList<Bitmap> postImages){
this.postStatuses = postStatuses;
this.postImages = postImages;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View customViewForDisplayingFeed = inflater.inflate(R.layout.recycler_list_users_feed,parent,false);
return new ViewHolder(customViewForDisplayingFeed);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
String status = postStatuses.get(position);
Bitmap image = postImages.get(position);
holder.postImage.setImageBitmap(image);
holder.postStatus.setText(status);
}
#Override
public int getItemCount() {
return postStatuses.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder{
ImageView postImage;
TextView postStatus
public ViewHolder(View itemView) {
super(itemView);
postImage = itemView.findViewById(R.id.userFeedImageListItem);
postStatus = itemView.findViewById(R.id.userFeedPostListItem);
}
}
}
Sorry for the ident, i edit this in a phone
I was able to solve my problem via making changes in my main activity's home page
<android.support.constraint.ConstraintLayout 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=".userTimeLine">
<View
android:id="#+id/view3"
style="#style/Divider"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:background="#f0f1f1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view3"
app:srcCompat="#drawable/usericon" />
<TextView
android:id="#+id/TIMELINE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="TIMELINE"
android:textColor="#android:color/black"
app:layout_constraintBottom_toBottomOf="#+id/view3"
app:layout_constraintEnd_toStartOf="#+id/view3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/view3"
app:layout_constraintTop_toTopOf="#+id/view3" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="USERNAME"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView3" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="170dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username" />
</android.support.constraint.ConstraintLayout>