Recycler view does not show up - java

I am having problem with my recyclerview I builed an app in android studio which suppose to create contacts and watch their cards using cardview and recyclerview the issue is that the list of contacts is not shown instead I am seeing a white screen
so here is my code:
import android.net.sip.SipSession;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.squareup.picasso.Picasso;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.List;
/*Connect contact list to
*
* */
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactViewHolder> {
private List<Contact> contacts;
public ContactAdapter(List<Contact> contacts) {
this.contacts = contacts;
}
interface ContactsListener{
void onContactClicked(int position,View view);
}
ContactsListener listener;
public void setListener(ContactsListener listener){
this.listener=listener;
}
public class ContactViewHolder extends RecyclerView.ViewHolder {
ImageView contactpicture;
TextView contactname;
TextView contactphone;
TextView contactemail;
public ContactViewHolder(View itemview) {
super(itemview);
contactpicture = itemview.findViewById(R.id.card_image);
contactphone = itemview.findViewById(R.id.contact_email);
contactphone = itemview.findViewById(R.id.contact_phone);
contactname = itemview.findViewById(R.id.contact_name);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (listener != null)
listener.onContactClicked(getAdapterPosition(), view);
}
});
}
}
#Override
public ContactViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.contact_layout,parent,false);
ContactViewHolder holder=new ContactViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(ContactViewHolder holder,int position){
Contact contact=contacts.get(position);
holder.contactpicture.setImageBitmap(contact.getPhoto());
holder.contactname.setText(contact.getName());
holder.contactphone.setText(contact.getPhone());
holder.contactemail.setText(contact.getEmail());
}
#Override
public int getItemCount(){
return contacts.size();
}
}
package com.example.b_safe;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/*Define the list of contacts*/
public class ContactsList extends Activity {
#Override
protected void onCreate(#Nullable Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.layout.show_contacts_activity);//לבדוק שזה מתקיים
RecyclerView recyclerview=findViewById(R.id.contacts_list);
recyclerview.setHasFixedSize(true);
recyclerview.setLayoutManager(new LinearLayoutManager( this));//צריך להוסיף this
ContactManager manager=ContactManager.getInstance(this);
ContactAdapter adapter=new ContactAdapter(manager.getContacts());
recyclerview.setAdapter(adapter);
adapter.setListener(new ContactAdapter.ContactsListener() {
#Override
public void onContactClicked(int position, View view) {
}
});
}
}
package com.example.b_safe;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
/*Adds new member to the contacts list
*
*
* */
public class AddContactActivity extends AppCompatActivity{
Bitmap bitmap;
EditText nameEt,phone_numberEt,emailEt;
ImageView img;
final int CAMERA_REQUEST=1;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_contact_activity);
nameEt=findViewById(R.id.name_input);
phone_numberEt=findViewById(R.id.phone_input);
emailEt=findViewById(R.id.email_input);
img=findViewById(R.id.photo_result);
Button takepicture=findViewById(R.id.take_pic);
takepicture.setOnClickListener(new View.OnClickListener() {//Activation
#Override
public void onClick(View v) {
Intent camera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera,CAMERA_REQUEST);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CAMERA_REQUEST&&resultCode==RESULT_OK){ //checks if results where properly
bitmap=(Bitmap)data.getExtras().get("data");
img.setImageBitmap(bitmap);//saving as contact's photo
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {//Load menu type
getMenuInflater().inflate(R.menu.contact_menu,menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {//fulfill actions
switch(item.getItemId()){
case R.id.action_save:
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("Please confirm")
.setMessage("Would you like to save the following contact?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Contact contact=new Contact(nameEt.getText().toString(),phone_numberEt.getText().toString(),emailEt.getText().toString(),bitmap);
ContactManager manager=ContactManager.getInstance(AddContactActivity.this);
manager.addContact(contact);//Manager saved data
//Data zeroing
nameEt.setText("");
phone_numberEt.setText("");
emailEt.setText("");
img.setImageBitmap(null);
}})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(AddContactActivity.this,"The conatct saved",Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(AddContactActivity.this,"The conatct saved",Toast.LENGTH_SHORT).show();
}
}).show();
break;
case R.id.action_back:
finish();
}
return super.onOptionsItemSelected(item);//Loads activity
}
}
AdapterActivity is the subclass adapter AddContactActivity creates new contacts and the problem is with the ContactsList activity which holds the list and does not show up

Related

how to move from a fragment to a new activity when i clicked an item of recyclerview?

I am using recyclerview in fragment dynamically, now i want to open new activity on click of items with the same object / item.
AllCoursesFeagment.java
package com.example.learningapp.ui.NavigationDrawer.AllCourses;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.learningapp.Adapters.AllCoursesMyAdapter;
import com.example.learningapp.Interface.APIinterface;
import com.example.learningapp.Models.CourseListModel;
import com.example.learningapp.R;
import com.example.learningapp.Responses.CourseListResponse;
import com.example.learningapp.RetrofitAPIs.RetrofitAPI;
import com.example.learningapp.utility.ConstantData;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class AllCoursesFragment extends Fragment {
private RecyclerView recyclerView;
private List<CourseListModel> courseListModelList;
public AllCoursesFragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static AllCoursesFragment newInstance() {
return new AllCoursesFragment();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_all_courses,null);
recyclerView = view.findViewById(R.id.allCourseList_RV);
APIinterface apIinterface = RetrofitAPI.getClient().create(APIinterface.class);
Call<CourseListResponse> call = apIinterface.getAllCourses(ConstantData.AppKey);
call.enqueue(new Callback<CourseListResponse>() {
#Override
public void onResponse(Call<CourseListResponse> call, Response<CourseListResponse> response){
if (response.isSuccessful()){
courseListModelList = response.body().getCourseList();
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(new AllCoursesMyAdapter(getActivity(),courseListModelList));
}
}
#Override
public void onFailure(Call<CourseListResponse> call, Throwable t) {
Toast.makeText(getActivity(),"Something went wrong",Toast.LENGTH_LONG).show();
}
});
return view;
}
}
AllCoursesMyAdapter.java
This is my adapter class.
package com.example.learningapp.Adapters;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.learningapp.Activities.CheckoutActivity;
import com.example.learningapp.Models.CourseListModel;
import com.example.learningapp.R;
import java.util.List;
public class AllCoursesMyAdapter extends RecyclerView.Adapter<AllCoursesMyAdapter.RecyclerVH> {
Context context;
List<CourseListModel> courseListModelList;
public AllCoursesMyAdapter(Context context, List<CourseListModel> courseListModelList) {
this.context = context;
this.courseListModelList = courseListModelList;
}
#NonNull
#Override
public RecyclerVH onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.single_row_design_allcourses,parent,false);
return new RecyclerVH(view);
}
#Override
public void onBindViewHolder(#NonNull RecyclerVH holder, int position) {
final CourseListModel courseListModel = courseListModelList.get(position);
holder.courseTitle.setText(courseListModel.getCourseName());
holder.courseDesc.setText(courseListModel.getCourseDescription());
holder.buyBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
moveToNewActivity();
//Toast.makeText(context,"Item Clicked"+position,Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, CheckoutActivity.class);
intent.putExtra("coursetitle",courseListModel.getCourseName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
}
private void moveToNewActivity () {
Activity activity = new Activity();
Intent i = new Intent(activity, CheckoutActivity.class);
context.startActivity(i);
((Activity) context).overridePendingTransition(0, 0);
}
#Override
public int getItemCount() {
return courseListModelList.size();
}
public class RecyclerVH extends RecyclerView.ViewHolder {
TextView courseTitle,courseDesc;
Button buyBtn;
public RecyclerVH(#NonNull View itemView) {
super(itemView);
courseTitle = itemView.findViewById(R.id.course_title);
courseDesc = itemView.findViewById(R.id.course_desc);
buyBtn = itemView.findViewById(R.id.btn_buycourse);
}
}
}
I'm gettng crashed when i clicked item
holder.buyBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
moveToNewActivity();
//Toast.makeText(context,"Item Clicked"+position,Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, CheckoutActivity.class);
intent.putExtra("coursetitle",courseListModel.getCourseName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
Here i am using a stored list of objects and now i want to move to the new activity when i clicked on an item with given position, but i am not able to do that.
private void moveToNewActivity () {
Activity activity = new Activity(); //this is wrong, delete this
...
}
you can't and shouldn't create an instance of an activity like this, it's something the OS has to schedule and handle for you.
you already seem to have context defined somewhere, so that means:
private void moveToNewActivity () {
Intent i = new Intent(context, CheckoutActivity.class);
context.startActivity(i);
...
}
so that means:
#Override
public void onClick(View v) {
moveToNewActivity();
}

Deleting item from listview behaving strange

I have a listview that extends base adapter. There is a delete button on every list item. When the delete button is clicked then the list item should be deleted. But when I try to do so listview behaves strangely. The delete button is causing the main problem. Sometimes the list is becoming double and sometimes app is crashing. I am trying to add a delete button to the item of the listview. When someone clicks on the button then the list item will be deleted and it will delete the item also from firebase.
I am trying to achieve this.
Sorry for my bad English. Advance thanks for your help.
package com.owoshopkeeperpanel.adapters;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.cepheuen.elegantnumberbutton.view.ElegantNumberButton;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.owoshopkeeperpanel.Interface.ItemClickListener;
import com.owoshopkeeperpanel.Model.Cart;
import com.owoshopkeeperpanel.Prevalent.Prevalent;
import com.owoshopkeeperpanel.R;
import java.util.ArrayList;
public class CartListAdapter extends BaseAdapter {
private Context mCtx;
private ArrayList<Cart> cartList;
final DatabaseReference cartListRef = FirebaseDatabase.getInstance().getReference().child("Cart List");
public CartListAdapter(Context mCtx, ArrayList<Cart> cartList) {
this.mCtx = mCtx;
this.cartList = cartList;
}
#Override
public int getCount() {
return cartList.size();
}
#Override
public Object getItem(int position) {
return cartList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Cart cart = cartList.get(position);
if(convertView==null) {
LayoutInflater layoutInflater = (LayoutInflater) mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.cart_items_sample, null);
}
ImageView delete = convertView.findViewById(R.id.cart_item_delete);
ImageView cart_product_image = convertView.findViewById(R.id.cart_product_image);
TextView cart_product_name = convertView.findViewById(R.id.cart_product_name);
TextView cart_product_quantity = convertView.findViewById(R.id.cart_product_quantity);
TextView cart_product_price = convertView.findViewById(R.id.cart_product_price);
ElegantNumberButton cart_item_change_button = convertView.findViewById(R.id.cart_item_change_btn);
Glide.with(mCtx).load(cart.getProduct_image()).into(cart_product_image);
cart_product_name.setText(cart.getProduct_name());
cart_product_quantity.setText(cart.getProduct_price()+" × "+cart.getNeeded_quantity());
double product_total_price = Double.parseDouble(cart.getProduct_price()) * Double.parseDouble(cart.getNeeded_quantity());
cart_product_price.setText("৳ "+String.valueOf(product_total_price));
cart_item_change_button.setNumber(cart.getNeeded_quantity());
delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mCtx);
alertDialogBuilder.setMessage("Are you sure you want to remove this item from cart ?");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
cartListRef.child(Prevalent.currentOnlineUser.getPhone())
.child(String.valueOf(cart.getProduct_id()))
.removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful())
{
Toast.makeText(mCtx, String.valueOf(cartList.size()), Toast.LENGTH_LONG).show();
cartList.remove(cart);
notifyDataSetChanged();
}
}
});
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
});
return convertView;
}
}

How can i delete documents on firestore?

I need your help. I need your advice for about firestore delete document. I have been working for 2 days this find codes. But everyone told it theoretically. As a last resort, I wanted to write here. How can i get position value ? And how can i delete documents on firestore ? Thank you so much for now your replies...
GorevRecyclerAdapter.java
package com.example.oztekapp;
import android.content.Intent;
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.ArrayList;
public class GorevRecyclerAdapter extends RecyclerView.Adapter<GorevRecyclerAdapter.PostHolder> {
private ArrayList <String> adliyeList;
private ArrayList <String> gorevbaslikList;
private ArrayList <String> gorevkonuList;
private ArrayList <String> gorevsaatilist;
private ArrayList <String> gorevtarihiList;
private ArrayList <String> useremailList;
public GorevRecyclerAdapter(ArrayList<String> adliyeList, ArrayList<String> gorevbaslikList, ArrayList<String> gorevkonuList, ArrayList<String> gorevsaatilist, ArrayList<String> gorevtarihiList, ArrayList<String> useremailList) {
this.adliyeList = adliyeList;
this.gorevbaslikList = gorevbaslikList;
this.gorevkonuList = gorevkonuList;
this.gorevsaatilist = gorevsaatilist;
this.gorevtarihiList = gorevtarihiList;
this.useremailList = useremailList;
}
#NonNull
#Override
public PostHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.recycler_row,parent,false);
return new PostHolder(view);
}
#Override
public void onBindViewHolder(#NonNull PostHolder holder, int position) {
holder.useremail.setText(useremailList.get(position));
holder.adliye.setText(adliyeList.get(position));
holder.gorevbaslik.setText(gorevbaslikList.get(position));
holder.gorevkonusu.setText(gorevkonuList.get(position));
holder.gorevtarihi.setText(gorevtarihiList.get(position));
holder.gorevsaati.setText(gorevsaatilist.get(position));
}
#Override
public int getItemCount() {
return useremailList.size();
}
class PostHolder extends RecyclerView.ViewHolder{
TextView adliye, gorevkonusu, gorevbaslik, gorevsaati, gorevtarihi, useremail;
public PostHolder(#NonNull final View itemView) {
super(itemView);
adliye = itemView.findViewById(R.id.adliyeTextView);
gorevbaslik = itemView.findViewById(R.id.gorevBaslikTextView);
gorevkonusu = itemView.findViewById(R.id.gorevKonuTextView);
gorevtarihi = itemView.findViewById(R.id.gorevTarihTextView);
gorevsaati = itemView.findViewById(R.id.gorevSaatTextView);
useremail = itemView.findViewById(R.id.userEmailTextView);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent (itemView.getContext(), GorevDetayActivity.class);
intent.putExtra("gorevbaslik", gorevbaslikList.get(getAdapterPosition()));
intent.putExtra("gorevkonu", gorevkonuList.get(getAdapterPosition()));
intent.putExtra("gorevtarihi", gorevtarihiList.get(getAdapterPosition()));
intent.putExtra("gorevsaati", gorevsaatilist.get(getAdapterPosition()));
v.getContext().startActivity(intent);
}
});
}
}
public void deleteItem(int position){
getSnapshots().getSnapshot(position).getReference().delete();
notifyDataSetChanged();
}
}
and GorevDetayActivity.java
package com.example.oztekapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.StorageReference;
import java.util.ArrayList;
public class GorevDetayActivity extends AppCompatActivity {
private EditText gorevbaslik,gorevkonu,gorevsaat,gorevtarih;
private Button guncelle;
private Spinner adliye;
private ArrayAdapter arrayAdapter;
private AlertDialog.Builder alertDialog;
private FirebaseFirestore firestore;
private ArrayList<String> adliyeList;
private ArrayList <String> gorevbaslikList;
private ArrayList <String> gorevkonuList;
private ArrayList <String> gorevsaatilist;
private ArrayList <String> gorevtarihiList;
private ArrayList <String> useremailList;
private GorevRecyclerAdapter gorevRecyclerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gorev_detay);
gorevbaslik = findViewById(R.id.detaygorevbaslik);
gorevkonu = findViewById(R.id.detaygorevkonusu);
gorevtarih = findViewById(R.id.detaytarih);
gorevsaat = findViewById(R.id.detaysaat);
adliye = findViewById(R.id.detayadliye);
firestore = FirebaseFirestore.getInstance();
gorevRecyclerAdapter = new GorevRecyclerAdapter(adliyeList,gorevbaslikList,gorevkonuList,gorevsaatilist,gorevtarihiList,useremailList);
Intent i = getIntent();
String gorevbasligi = i.getStringExtra("gorevbaslik");
String gorevkonusu = i.getStringExtra("gorevkonu");
String gorevtarihi = i.getStringExtra("gorevtarihi");
String gorevsaati = i.getStringExtra("gorevsaati");
gorevbaslik.setText(gorevbasligi);
gorevkonu.setText(gorevkonusu);
gorevtarih.setText(gorevtarihi);
gorevsaat.setText(gorevsaati);
arrayAdapter = ArrayAdapter.createFromResource(this,R.array.adliyeler,android.R.layout.simple_dropdown_item_1line);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
adliye.setAdapter(arrayAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menudetay,menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(#NonNull final MenuItem item) {
if (item.getItemId() == R.id.gorevsil)
{
alertDialog = new AlertDialog.Builder(GorevDetayActivity.this);
alertDialog.setTitle("Görev Sil");
alertDialog.setMessage("Görevi silmek istediğinize emin misiniz ?");
alertDialog.setPositiveButton("Evet", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
firestore.collection("Görevler").document().delete().addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Intent intent = new Intent(GorevDetayActivity.this,MainActivity.class);
startActivity(intent);
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(GorevDetayActivity.this, e.getLocalizedMessage().toString(), Toast.LENGTH_LONG).show();
}
});
}
}).setNegativeButton("Vazgeç", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.create().show();
}
return super.onOptionsItemSelected(item);
}
}

E/RecyclerView: No adapter attached; skipping layout / On google play billing

Hey i want to implement google billing into my app but everytime i open the activty where the button is to call my purchase the Console prints
"E/RecyclerView: No adapter attached; skipping layout"
I have a ProductAdapterclass my Information Activity where the button is located.
package com.test.smartbuyapp.Adapter;
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.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingFlowParams;
import com.android.billingclient.api.SkuDetails;
import com.test.smartbuyapp.InformationActivity;
import com.test.smartbuyapp.Interface.IProductClickListener;
import com.test.smartbuyapp.R;
import java.util.List;
public class MyProductAdapter extends RecyclerView.Adapter<MyProductAdapter.MyViewHolder> {
InformationActivity informationActivity;
List<SkuDetails> skuDetailsList;
BillingClient billingClient;
public MyProductAdapter(InformationActivity informationActivity, List<SkuDetails> skuDetailsList, BillingClient billingClient) {
this.informationActivity = informationActivity;
this.skuDetailsList = skuDetailsList;
this.billingClient = billingClient;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int viewType) {
View itemView = LayoutInflater.from(informationActivity.getBaseContext())
.inflate(R.layout.layout_product_item,viewGroup,false);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
holder.txt_product.setText(skuDetailsList.get(position).getTitle());
//Product click
holder.setiProductClickListener(new IProductClickListener() {
#Override
public void onProductClickListerner(View view, int position) {
//Launch Billing flow
BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetailsList.get(position))
.build();
billingClient.launchBillingFlow(informationActivity,billingFlowParams);
}
});
}
#Override
public int getItemCount() {
return skuDetailsList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView txt_product;
IProductClickListener iProductClickListener;
public void setiProductClickListener(IProductClickListener iProductClickListener) {
this.iProductClickListener = iProductClickListener;
}
public MyViewHolder(#NonNull View itemView) {
super(itemView);
txt_product = (TextView) itemView.findViewById(R.id.txt_product_name);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
iProductClickListener.onProductClickListerner(v, getAdapterPosition());
}
}
}
And My Informationactivity
package com.test.smartbuyapp;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchasesUpdatedListener;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsParams;
import com.android.billingclient.api.SkuDetailsResponseListener;
import com.test.smartbuyapp.Adapter.MyProductAdapter;
import java.util.Arrays;
import java.util.List;
public class InformationActivity extends AppCompatActivity implements PurchasesUpdatedListener {
BillingClient billingClient;
Button loadProduct;
RecyclerView recyclerProduct;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_information);
setupBillingClient();
//View
loadProduct = (Button) findViewById(R.id.btn_load_product);
recyclerProduct = (RecyclerView)findViewById(R.id.recycler_product);
recyclerProduct.setLayoutManager(new LinearLayoutManager(this));
recyclerProduct.setHasFixedSize(true);
//Event
loadProduct.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(billingClient.isReady()) {
SkuDetailsParams params = SkuDetailsParams.newBuilder()
.setSkusList(Arrays.asList("adfree"))
.setType(BillingClient.SkuType.INAPP)
.build();
billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
#Override
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> list) {
if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK){
loadProductToRecyclerView(list);
}else{
Toast.makeText(InformationActivity.this,"Cannot query product",Toast.LENGTH_SHORT);
}
}
});
}else {
Toast.makeText(InformationActivity.this,"Billing client not Ready",Toast.LENGTH_SHORT);
}
}
});
//////////// Toolbar //////////////////////////////////////////////////////////////
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("Information");
}
private void loadProductToRecyclerView(List<SkuDetails> list) {
MyProductAdapter adapter= new MyProductAdapter(this,list,billingClient);
recyclerProduct.setAdapter(adapter);
}
private void setupBillingClient() {
billingClient = BillingClient.newBuilder(this).setListener(this).enablePendingPurchases().build();
billingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(BillingResult billingResult) {
if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK){
Toast.makeText(InformationActivity.this,"Sucessfully Billing Connect",Toast.LENGTH_SHORT);
}else {
Toast.makeText(InformationActivity.this,"Failed to Billing Connect"+billingResult.getResponseCode(),Toast.LENGTH_SHORT);
}
}
#Override
public void onBillingServiceDisconnected() {
Toast.makeText(InformationActivity.this,"You are disconnected from billing",Toast.LENGTH_SHORT);
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home:
startActivity(new Intent(com.test.smartbuyapp.InformationActivity.this, ListMainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
return true;
}
return false;
}
public void PrivacyPerform(View view) {
TextView agb = (TextView) findViewById(R.id.AGB);
agb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://sites.google.com/view/smartbuyapp/"));
startActivity(intent);
}
});
}
#Override
public void onPurchasesUpdated(BillingResult billingResult, #Nullable List<Purchase> list) {
//Here if user clicks Buy, we will receive data
Toast.makeText(InformationActivity.this,"Purchase item",Toast.LENGTH_SHORT);
}
}

Cannot Resolve OnClickListener

I am a highschool student in an Android App Development class. I was making an introduction slider for my app with buttons to go to the next activity. I unfortunately get the error cannot resolve symbol 'OnClickListener'. I made sure that this was all written under the OnCreate(); method and included the import statement for the OnClickListener(); but it still cannot resolve the symbol. Is there another import statement or was this misplaced? Below you will find my code.
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class SecondActivity extends AppCompatActivity {
private ViewPagerAdapter viewPagerAdapter;
private ViewPager viewPager;
private IntroManager introManager;
private TextView [] dots;
private LinearLayout dotsLayout;
private int[] layouts;
Button next,skip;
View view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
introManager = new IntroManager(this);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.second_activity);
if(!introManager.Check())
{
introManager.setFirst(false);
Intent intent = new Intent(SecondActivity.this,ThirdActivity.class);
startActivity(intent);
finish();
}
layouts= new int[]{R.layout.second_activity,R.layout.third_activity,R.layout.fourth_activity,R.layout.fifth_activity};
if(Build.VERSION.SDK_INT>=21){
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_FULLSCREEN);
}
viewPager = (ViewPager) findViewById(R.id.view_pager);
dotsLayout= (LinearLayout) findViewById(R.id.layoutdots);
skip = (Button) findViewById(R.id.btn_skip);
next = (Button) findViewById(R.id.btn_next);
addBottomDots(0);
viewPagerAdapter= new ViewPagerAdapter();
viewPager.setAdapter(viewPagerAdapter);
viewPager.addOnPageChangeListener(viewListener);
skip.setOnClickListener(new view.OnClickListener(){
#Override
public void onClick(View view){
Intent intent = new Intent(SecondActivity.this,FifthActivity.class);
startActivity(intent);
finish();
}
});
next.setOnClickListener(new view.OnClickListener(){
#Override
public void onClick(View view){
int current = getItem(+1);
if(current<layouts.length){
viewPager.setCurrentItem(current);
}
else
{
Intent intent = new Intent(SecondActivity.this,ThirdActivity.class);
startActivity(intent);
finish();
}
}
});
}
private void addBottomDots(int position){
dots = new TextView[layouts.length];
int [] colorActive = getResources().getIntArray(R.array.dot_active);
int [] colorInactive = getResources().getIntArray(R.array.dot_inactive);
dotsLayout.removeAllViews();
for (int i = 0; i<dots.length; i++){
dots[i]= new TextView(this);
dots[i].setText(Html.fromHtml("&#8226;"));
dots[i].setTextSize(35);
dots[i].setTextColor(colorInactive[position]);
dotsLayout.addView(dots[i]);
}
if(dots[position].length()>0){
dots[position].setTextColor(colorActive[position]);
}
}
private int getItem(int i){
return viewPager.getCurrentItem() + 1;
}
ViewPager.OnPageChangeListener viewListener = new ViewPager.OnPageChangeListener(){
#Override
public void onPageScrolled(int position, float positionOffeet, int positionOffeetPixels){
}
#Override
public void onPageSelected(int position)
{
addBottomDots(position);
if (position==layouts.length-1){
next.setText("PROCEED");
skip.setVisibility(View.GONE);
}else{
next.setText("NEXT");
skip.setVisibility(View.VISIBLE);
}
}
#Override
public void onPageScrollStateChanged(int state)
{}
}
;
public void changetatusColor(){
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
}
public class ViewPagerAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;
#Override
public Object instantiateItem(ViewGroup container, int position){
layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = LayoutInflater.inflate(layouts[position],container,false);
container.addView(v);
return v;
}
#Override
public int getCount(){
return 0;
}
#Override
public boolean isViewFromObject(View view,Object object){
return view==object;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object){
View v = (View) object;
container.removeView(v);
}
}
}
Do only one of those:
import android.view.View;
// note that View is uppercase
.setOnClickListener(new View.OnClickListener() {
import android.view.View.OnClickListener;
.setOnClickListener(new OnClickListener() {

Categories

Resources