views bellow recyclerview are giving null value thus unable to set visibility of that views











up vote
-1
down vote

favorite
1












views bellow recyclerview are giving null value thus unable to set visibility of that views i tried to find view by every method but it is always giving null pointers exception
its giving me this "Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference"



 <?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activity.MenuListActivity"
tools:showIn="@layout/app_bar_menu_lis"
android:background="@drawable/contentbg">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/hiddenCart"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="-4dp">

</android.support.v7.widget.RecyclerView>

<android.support.constraint.ConstraintLayout
android:id="@+id/hiddenCart"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/totalTV"
android:layout_width="100dp"
android:layout_height="25dp"
android:layout_marginStart="12dp"
android:layout_marginTop="59dp"
android:text="sub"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/disTotal"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginStart="13dp"
android:layout_marginTop="20dp"
android:fontFamily="@font/playfair_display"
android:text="Total"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/cartIconIV"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@mipmap/ic_launcher" />

</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>


This my activity



enter code hepublic class MenuListActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private List<MenuIT> productList;
private MenuItemAdapter adapter;
private FirebaseFirestore db;
public TextView tv;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_list);
recyclerView=(RecyclerView)findViewById(R.id.recycleView);
db=FirebaseFirestore.getInstance();

recyclerView.setHasFixedSize(true);
productList=new ArrayList<>();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter=new MenuItemAdapter(this,productList);
recyclerView.setAdapter(adapter);


tv=(TextView) findViewById(R.id.disTotal);



db.collection("menu").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

try{
if(!queryDocumentSnapshots.isEmpty()){
List<DocumentSnapshot> list=queryDocumentSnapshots.getDocuments();

for(DocumentSnapshot d:list){
MenuIT menuItem=d.toObject(MenuIT.class);
productList.add(menuItem);
}
adapter.notifyDataSetChanged();
}}
catch (Exception e){
Toast.makeText(MenuListActivity.this, ""+e.toString(), Toast.LENGTH_SHORT).show();
}
}

});






}




public void getCount(int count)
{
if(count>0)
{

tv.setVisibility(View.GONE);
}
}


}
This my adapter for recyclerview



public class MenuItemAdapter extends RecyclerView.Adapter<MenuItemAdapter.ViewHolder> {
private Context mContext;
private FirebaseFirestore db;
private List<MenuIT> productList;
private HashMap itemRecord;


public MenuItemAdapter(Context mContext, List<MenuIT> productList) {
this.mContext = mContext;
this.productList = productList;

}




@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {

LayoutInflater inflater= LayoutInflater.from(mContext);
View view=inflater.inflate(R.layout.menu_recycler_view,null);
ViewHolder holder=new ViewHolder(view);
return holder;
}

@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int position) {
final MenuIT menuItem=productList.get(position);
final ItemMap itemMap=new ItemMap();
final MenuListActivity menuL=new MenuListActivity();

itemRecord=itemMap.getItemRecord();
viewHolder.menuDescTV.setText(menuItem.getItemName());
db=FirebaseFirestore.getInstance();
viewHolder.itemprice.setText(String.valueOf(menuItem.getItemPrice()));
viewHolder.plusTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id=menuItem.getId();
Toast.makeText(mContext, ""+id, Toast.LENGTH_SHORT).show();
int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count<10 ) {
count++;
itemRecord.put(menuItem.getItemName(),count);
itemMap.setItemRecord(itemRecord);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);

}
if (count>0)
{
menuL.getCount(count);
}

}
});
viewHolder.minusTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count>0) {
count--;
itemRecord.put(menuItem.getItemName(),count);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);


}




}
});
}

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

public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView menuIV;
private TextView menuDescTV;
private ImageView plusTv;
private ImageView minusTV;
private TextView menuItemCount;
private TextView itemprice;




public ViewHolder(@NonNull View itemView) {
super(itemView);
menuIV=itemView.findViewById(R.id.menuIV);
menuDescTV=itemView.findViewById(R.id.menuDescTV);
plusTv=itemView.findViewById(R.id.plusTV);
minusTV=itemView.findViewById(R.id.minusTV);
db=FirebaseFirestore.getInstance();
menuItemCount=itemView.findViewById(R.id.menuItemCount);
itemprice=itemView.findViewById(R.id.itemPrice);









}

}


}










share|improve this question
























  • Show some code.
    – TheWanderer
    Nov 10 at 13:17










  • i added all the code above
    – akshat rai
    Nov 10 at 13:27










  • You can try to initialize your textview in getCount method.
    – ManishPrajapati
    Nov 10 at 15:07










  • still not working @m
    – akshat rai
    Nov 10 at 16:54















up vote
-1
down vote

favorite
1












views bellow recyclerview are giving null value thus unable to set visibility of that views i tried to find view by every method but it is always giving null pointers exception
its giving me this "Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference"



 <?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activity.MenuListActivity"
tools:showIn="@layout/app_bar_menu_lis"
android:background="@drawable/contentbg">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/hiddenCart"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="-4dp">

</android.support.v7.widget.RecyclerView>

<android.support.constraint.ConstraintLayout
android:id="@+id/hiddenCart"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/totalTV"
android:layout_width="100dp"
android:layout_height="25dp"
android:layout_marginStart="12dp"
android:layout_marginTop="59dp"
android:text="sub"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/disTotal"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginStart="13dp"
android:layout_marginTop="20dp"
android:fontFamily="@font/playfair_display"
android:text="Total"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/cartIconIV"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@mipmap/ic_launcher" />

</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>


This my activity



enter code hepublic class MenuListActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private List<MenuIT> productList;
private MenuItemAdapter adapter;
private FirebaseFirestore db;
public TextView tv;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_list);
recyclerView=(RecyclerView)findViewById(R.id.recycleView);
db=FirebaseFirestore.getInstance();

recyclerView.setHasFixedSize(true);
productList=new ArrayList<>();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter=new MenuItemAdapter(this,productList);
recyclerView.setAdapter(adapter);


tv=(TextView) findViewById(R.id.disTotal);



db.collection("menu").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

try{
if(!queryDocumentSnapshots.isEmpty()){
List<DocumentSnapshot> list=queryDocumentSnapshots.getDocuments();

for(DocumentSnapshot d:list){
MenuIT menuItem=d.toObject(MenuIT.class);
productList.add(menuItem);
}
adapter.notifyDataSetChanged();
}}
catch (Exception e){
Toast.makeText(MenuListActivity.this, ""+e.toString(), Toast.LENGTH_SHORT).show();
}
}

});






}




public void getCount(int count)
{
if(count>0)
{

tv.setVisibility(View.GONE);
}
}


}
This my adapter for recyclerview



public class MenuItemAdapter extends RecyclerView.Adapter<MenuItemAdapter.ViewHolder> {
private Context mContext;
private FirebaseFirestore db;
private List<MenuIT> productList;
private HashMap itemRecord;


public MenuItemAdapter(Context mContext, List<MenuIT> productList) {
this.mContext = mContext;
this.productList = productList;

}




@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {

LayoutInflater inflater= LayoutInflater.from(mContext);
View view=inflater.inflate(R.layout.menu_recycler_view,null);
ViewHolder holder=new ViewHolder(view);
return holder;
}

@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int position) {
final MenuIT menuItem=productList.get(position);
final ItemMap itemMap=new ItemMap();
final MenuListActivity menuL=new MenuListActivity();

itemRecord=itemMap.getItemRecord();
viewHolder.menuDescTV.setText(menuItem.getItemName());
db=FirebaseFirestore.getInstance();
viewHolder.itemprice.setText(String.valueOf(menuItem.getItemPrice()));
viewHolder.plusTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id=menuItem.getId();
Toast.makeText(mContext, ""+id, Toast.LENGTH_SHORT).show();
int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count<10 ) {
count++;
itemRecord.put(menuItem.getItemName(),count);
itemMap.setItemRecord(itemRecord);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);

}
if (count>0)
{
menuL.getCount(count);
}

}
});
viewHolder.minusTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count>0) {
count--;
itemRecord.put(menuItem.getItemName(),count);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);


}




}
});
}

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

public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView menuIV;
private TextView menuDescTV;
private ImageView plusTv;
private ImageView minusTV;
private TextView menuItemCount;
private TextView itemprice;




public ViewHolder(@NonNull View itemView) {
super(itemView);
menuIV=itemView.findViewById(R.id.menuIV);
menuDescTV=itemView.findViewById(R.id.menuDescTV);
plusTv=itemView.findViewById(R.id.plusTV);
minusTV=itemView.findViewById(R.id.minusTV);
db=FirebaseFirestore.getInstance();
menuItemCount=itemView.findViewById(R.id.menuItemCount);
itemprice=itemView.findViewById(R.id.itemPrice);









}

}


}










share|improve this question
























  • Show some code.
    – TheWanderer
    Nov 10 at 13:17










  • i added all the code above
    – akshat rai
    Nov 10 at 13:27










  • You can try to initialize your textview in getCount method.
    – ManishPrajapati
    Nov 10 at 15:07










  • still not working @m
    – akshat rai
    Nov 10 at 16:54













up vote
-1
down vote

favorite
1









up vote
-1
down vote

favorite
1






1





views bellow recyclerview are giving null value thus unable to set visibility of that views i tried to find view by every method but it is always giving null pointers exception
its giving me this "Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference"



 <?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activity.MenuListActivity"
tools:showIn="@layout/app_bar_menu_lis"
android:background="@drawable/contentbg">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/hiddenCart"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="-4dp">

</android.support.v7.widget.RecyclerView>

<android.support.constraint.ConstraintLayout
android:id="@+id/hiddenCart"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/totalTV"
android:layout_width="100dp"
android:layout_height="25dp"
android:layout_marginStart="12dp"
android:layout_marginTop="59dp"
android:text="sub"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/disTotal"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginStart="13dp"
android:layout_marginTop="20dp"
android:fontFamily="@font/playfair_display"
android:text="Total"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/cartIconIV"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@mipmap/ic_launcher" />

</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>


This my activity



enter code hepublic class MenuListActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private List<MenuIT> productList;
private MenuItemAdapter adapter;
private FirebaseFirestore db;
public TextView tv;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_list);
recyclerView=(RecyclerView)findViewById(R.id.recycleView);
db=FirebaseFirestore.getInstance();

recyclerView.setHasFixedSize(true);
productList=new ArrayList<>();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter=new MenuItemAdapter(this,productList);
recyclerView.setAdapter(adapter);


tv=(TextView) findViewById(R.id.disTotal);



db.collection("menu").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

try{
if(!queryDocumentSnapshots.isEmpty()){
List<DocumentSnapshot> list=queryDocumentSnapshots.getDocuments();

for(DocumentSnapshot d:list){
MenuIT menuItem=d.toObject(MenuIT.class);
productList.add(menuItem);
}
adapter.notifyDataSetChanged();
}}
catch (Exception e){
Toast.makeText(MenuListActivity.this, ""+e.toString(), Toast.LENGTH_SHORT).show();
}
}

});






}




public void getCount(int count)
{
if(count>0)
{

tv.setVisibility(View.GONE);
}
}


}
This my adapter for recyclerview



public class MenuItemAdapter extends RecyclerView.Adapter<MenuItemAdapter.ViewHolder> {
private Context mContext;
private FirebaseFirestore db;
private List<MenuIT> productList;
private HashMap itemRecord;


public MenuItemAdapter(Context mContext, List<MenuIT> productList) {
this.mContext = mContext;
this.productList = productList;

}




@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {

LayoutInflater inflater= LayoutInflater.from(mContext);
View view=inflater.inflate(R.layout.menu_recycler_view,null);
ViewHolder holder=new ViewHolder(view);
return holder;
}

@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int position) {
final MenuIT menuItem=productList.get(position);
final ItemMap itemMap=new ItemMap();
final MenuListActivity menuL=new MenuListActivity();

itemRecord=itemMap.getItemRecord();
viewHolder.menuDescTV.setText(menuItem.getItemName());
db=FirebaseFirestore.getInstance();
viewHolder.itemprice.setText(String.valueOf(menuItem.getItemPrice()));
viewHolder.plusTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id=menuItem.getId();
Toast.makeText(mContext, ""+id, Toast.LENGTH_SHORT).show();
int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count<10 ) {
count++;
itemRecord.put(menuItem.getItemName(),count);
itemMap.setItemRecord(itemRecord);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);

}
if (count>0)
{
menuL.getCount(count);
}

}
});
viewHolder.minusTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count>0) {
count--;
itemRecord.put(menuItem.getItemName(),count);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);


}




}
});
}

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

public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView menuIV;
private TextView menuDescTV;
private ImageView plusTv;
private ImageView minusTV;
private TextView menuItemCount;
private TextView itemprice;




public ViewHolder(@NonNull View itemView) {
super(itemView);
menuIV=itemView.findViewById(R.id.menuIV);
menuDescTV=itemView.findViewById(R.id.menuDescTV);
plusTv=itemView.findViewById(R.id.plusTV);
minusTV=itemView.findViewById(R.id.minusTV);
db=FirebaseFirestore.getInstance();
menuItemCount=itemView.findViewById(R.id.menuItemCount);
itemprice=itemView.findViewById(R.id.itemPrice);









}

}


}










share|improve this question















views bellow recyclerview are giving null value thus unable to set visibility of that views i tried to find view by every method but it is always giving null pointers exception
its giving me this "Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference"



 <?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activity.MenuListActivity"
tools:showIn="@layout/app_bar_menu_lis"
android:background="@drawable/contentbg">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/hiddenCart"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="-4dp">

</android.support.v7.widget.RecyclerView>

<android.support.constraint.ConstraintLayout
android:id="@+id/hiddenCart"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/totalTV"
android:layout_width="100dp"
android:layout_height="25dp"
android:layout_marginStart="12dp"
android:layout_marginTop="59dp"
android:text="sub"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/disTotal"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginStart="13dp"
android:layout_marginTop="20dp"
android:fontFamily="@font/playfair_display"
android:text="Total"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/cartIconIV"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@mipmap/ic_launcher" />

</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>


This my activity



enter code hepublic class MenuListActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private List<MenuIT> productList;
private MenuItemAdapter adapter;
private FirebaseFirestore db;
public TextView tv;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_list);
recyclerView=(RecyclerView)findViewById(R.id.recycleView);
db=FirebaseFirestore.getInstance();

recyclerView.setHasFixedSize(true);
productList=new ArrayList<>();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter=new MenuItemAdapter(this,productList);
recyclerView.setAdapter(adapter);


tv=(TextView) findViewById(R.id.disTotal);



db.collection("menu").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

try{
if(!queryDocumentSnapshots.isEmpty()){
List<DocumentSnapshot> list=queryDocumentSnapshots.getDocuments();

for(DocumentSnapshot d:list){
MenuIT menuItem=d.toObject(MenuIT.class);
productList.add(menuItem);
}
adapter.notifyDataSetChanged();
}}
catch (Exception e){
Toast.makeText(MenuListActivity.this, ""+e.toString(), Toast.LENGTH_SHORT).show();
}
}

});






}




public void getCount(int count)
{
if(count>0)
{

tv.setVisibility(View.GONE);
}
}


}
This my adapter for recyclerview



public class MenuItemAdapter extends RecyclerView.Adapter<MenuItemAdapter.ViewHolder> {
private Context mContext;
private FirebaseFirestore db;
private List<MenuIT> productList;
private HashMap itemRecord;


public MenuItemAdapter(Context mContext, List<MenuIT> productList) {
this.mContext = mContext;
this.productList = productList;

}




@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {

LayoutInflater inflater= LayoutInflater.from(mContext);
View view=inflater.inflate(R.layout.menu_recycler_view,null);
ViewHolder holder=new ViewHolder(view);
return holder;
}

@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int position) {
final MenuIT menuItem=productList.get(position);
final ItemMap itemMap=new ItemMap();
final MenuListActivity menuL=new MenuListActivity();

itemRecord=itemMap.getItemRecord();
viewHolder.menuDescTV.setText(menuItem.getItemName());
db=FirebaseFirestore.getInstance();
viewHolder.itemprice.setText(String.valueOf(menuItem.getItemPrice()));
viewHolder.plusTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id=menuItem.getId();
Toast.makeText(mContext, ""+id, Toast.LENGTH_SHORT).show();
int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count<10 ) {
count++;
itemRecord.put(menuItem.getItemName(),count);
itemMap.setItemRecord(itemRecord);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);

}
if (count>0)
{
menuL.getCount(count);
}

}
});
viewHolder.minusTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


int count=Integer.parseInt(viewHolder.menuItemCount.getText().toString());
if(count>0) {
count--;
itemRecord.put(menuItem.getItemName(),count);
Toast.makeText(mContext, ""+itemRecord.get(menuItem.getItemName()), Toast.LENGTH_SHORT).show();
viewHolder.menuItemCount.setText("" + count);


}




}
});
}

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

public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView menuIV;
private TextView menuDescTV;
private ImageView plusTv;
private ImageView minusTV;
private TextView menuItemCount;
private TextView itemprice;




public ViewHolder(@NonNull View itemView) {
super(itemView);
menuIV=itemView.findViewById(R.id.menuIV);
menuDescTV=itemView.findViewById(R.id.menuDescTV);
plusTv=itemView.findViewById(R.id.plusTV);
minusTV=itemView.findViewById(R.id.minusTV);
db=FirebaseFirestore.getInstance();
menuItemCount=itemView.findViewById(R.id.menuItemCount);
itemprice=itemView.findViewById(R.id.itemPrice);









}

}


}







android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 13:27

























asked Nov 10 at 13:16









akshat rai

11




11












  • Show some code.
    – TheWanderer
    Nov 10 at 13:17










  • i added all the code above
    – akshat rai
    Nov 10 at 13:27










  • You can try to initialize your textview in getCount method.
    – ManishPrajapati
    Nov 10 at 15:07










  • still not working @m
    – akshat rai
    Nov 10 at 16:54


















  • Show some code.
    – TheWanderer
    Nov 10 at 13:17










  • i added all the code above
    – akshat rai
    Nov 10 at 13:27










  • You can try to initialize your textview in getCount method.
    – ManishPrajapati
    Nov 10 at 15:07










  • still not working @m
    – akshat rai
    Nov 10 at 16:54
















Show some code.
– TheWanderer
Nov 10 at 13:17




Show some code.
– TheWanderer
Nov 10 at 13:17












i added all the code above
– akshat rai
Nov 10 at 13:27




i added all the code above
– akshat rai
Nov 10 at 13:27












You can try to initialize your textview in getCount method.
– ManishPrajapati
Nov 10 at 15:07




You can try to initialize your textview in getCount method.
– ManishPrajapati
Nov 10 at 15:07












still not working @m
– akshat rai
Nov 10 at 16:54




still not working @m
– akshat rai
Nov 10 at 16:54

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239324%2fviews-bellow-recyclerview-are-giving-null-value-thus-unable-to-set-visibility-of%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239324%2fviews-bellow-recyclerview-are-giving-null-value-thus-unable-to-set-visibility-of%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?