Data is duplicating when navigate back to previous fragment - java

I am using navigation component in my app I have 2 fragments one fragments list of items and another shows detail of an item when user clicks on an item in fragments 1 it goes to detail fragment and when I switch back to first fragment then all the listing duplicates again.
Below is my code:
CakeFragment.java
public class CakeFragment extends Fragment {
List<AllCakes> allCakeList = new ArrayList<>();
AllCakesAdapter adapter;
BottomNavigationView navView;
FragmentCakeBinding fragmentCakeBinding;
public CakeFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
fragmentCakeBinding = FragmentCakeBinding.inflate(inflater,container,false);
navView = getActivity().findViewById(R.id.navView);
navView.setVisibility(View.GONE);
getAllCakes();
return fragmentCakeBinding.getRoot();
}
private void getAllCakes(){
Retrofit retrofit = RetrofitClient.getInstance();
ApiService apiService = retrofit.create(ApiService.class);
Call<List<AllCakes>> call = apiService.getAllCake();
call.enqueue(new Callback<List<AllCakes>>() {
#Override
public void onResponse(Call<List<AllCakes>> call, Response<List<AllCakes>> response) {
fragmentCakeBinding.cakeProgress.setVisibility(View.INVISIBLE);
fragmentCakeBinding.allCakeRecycler.setHasFixedSize(true);
fragmentCakeBinding.allCakeRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
allCakeList.addAll(response.body());
adapter = new AllCakesAdapter(getActivity(),allCakeList);
fragmentCakeBinding.allCakeRecycler.setAdapter(adapter);
}
#Override
public void onFailure(Call<List<AllCakes>> call, Throwable t) {
fragmentCakeBinding.cakeProgress.setVisibility(View.INVISIBLE);
TastyToast.makeText(getActivity(),t.getMessage(),TastyToast.LENGTH_SHORT,TastyToast.ERROR).show();
}
});
}
}
AllCakesAdapter.java
public class AllCakesAdapter extends RecyclerView.Adapter<AllCakesAdapter.ViewHolder> {
Context context;
List<AllCakes> allCakeList;
public AllCakesAdapter(Context context, List<AllCakes> allCakeList) {
this.context = context;
this.allCakeList = allCakeList;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.allcakes_row,parent,false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
AllCakes model = allCakeList.get(position);
Glide.with(context).load(model.getImgurl()).into(holder.allCakeImg);
holder.allCakeName.setText(model.getName());
holder.cakeDisPrice.setPaintFlags(holder.cakeDisPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.moreCake.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
NavController navController = Navigation.findNavController((Activity) context,R.id.fragment);
navController.navigate(R.id.cakeDetailFragment);
}
});
}
#Override
public int getItemCount() {
return allCakeList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView allCakeImg;
Button moreCake;
TextView allCakeName;
public ViewHolder(#NonNull View itemView) {
super(itemView);
allCakeImg = itemView.findViewById(R.id.allCakeImg);
moreCake = itemView.findViewById(R.id.moreCake);
allCakeName = itemView.findViewById(R.id.allCakeName);
}
}
}
CakeDetailFragment.java
public class CakeDetailFragment extends Fragment {
FragmentCakeDetailBinding fragmentCakeDetailBinding;
public CakeDetailFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
fragmentCakeDetailBinding = FragmentCakeDetailBinding.inflate(inflater,container,false);
return fragmentCakeDetailBinding.getRoot();
}
}
Why is this happening?

private void getAllCakes(){
...
allCakeList.addAll(response.body());
adapter = new AllCakesAdapter(getActivity(),allCakeList);
fragmentCakeBinding.allCakeRecycler.setAdapter(adapter);
}
...
you're calling:
allCakeList.addAll(response.body());
every time without clearing your list out.
you have to clear that list:
allCakeList.clear();
allCakeList.addAll(response.body());
this is something you can easily determine yourself by just putting a breakpoint on your allCakeList to see what's inside it, if you haven't ever done this before, you should consider trying it out

Try the following and see if it solves your issue
CakeFragment.java
allCakeList.clear();
allCakeList.addAll(response.body());
//rest of the logic remains same

Related

How can I use RecyclerView in fragments using Firestore - Android

I want to use a recyclerView to show some products, they are inside firebase-firestore and, to get them I use a query. After this, I call the adapter to show but nothing appears.
You can see my adapter where:
public class ProdutoRecyclerAdapter extends FirestoreRecyclerAdapter <Produto, ProdutoRecyclerAdapter.ProdutoHolder> {
public ProdutoRecyclerAdapter(#NonNull FirestoreRecyclerOptions<Produto> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull ProdutoHolder produtoHolder, int i, #NonNull Produto produto) {
produtoHolder.tNome.setText(produto.getNomeP());
produtoHolder.tPontos.setText(String.valueOf(produto.getPontosP()));
}
#NonNull
#Override
public ProdutoHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.lista_produtos,parent,false);
ProdutoHolder holder = new ProdutoHolder(v);
return holder;
}
class ProdutoHolder extends RecyclerView.ViewHolder{
TextView tNome;
TextView tPontos;
public ProdutoHolder(#NonNull View itemView) {
super(itemView);
tNome = itemView.findViewById(R.id.nomeP);
tPontos= itemView.findViewById(R.id.pontosP);
}
}
And here there is my fragment:
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.store,null);
toolbar = view.findViewById(R.id.toolbar_loja);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
Query query = produtoRef.orderBy("pontos");
FirestoreRecyclerOptions<Produto> option = new FirestoreRecyclerOptions.Builder<Produto>()
.setQuery(query, Produto.class)
.build();
adapter = new ProdutoRecyclerAdapter(option);
recyclerView = (RecyclerView) view.findViewById(R.id.produtos_list);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(adapter);
return view;
}
#Override
public void onStart() {
super.onStart();
adapter.startListening();
}
#Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
I don't have any error, but nothing appears on the screen, and I already did the debug and I know the variables are passing the right value.
At your adapter, you should have the override of getItemCount() and getItem()
/**
* Gets the item at the specified position from the backing snapshot array.
*
* #see ObservableSnapshotArray#get(int)
*/
#NonNull
public T getItem(int position) {
return mSnapshots.get(position);
}
#Override
public int getItemCount() {
return mSnapshots.isListening(this) ? mSnapshots.size() : 0;
}
where mSnapshots is your array of data.
Docuementation here

showing RecyclerView on fragment with data from Firebase

I'm having a problem with making a RecycleView in a fragment with data from Firebase. I expect the app to show the RecycleView after I clicked on a button to change from one fragment to the RecycleView fragment, but it does change the showed fragment but it does not show anything.
I know there are plenty of questions like this but I don't seem to find the correct solution to this problem.
I've made everything needed for a Firebase RecyclerView, and also tried to build it inside an activity instead fragment and it did work, but not with the fragment.
I've tried to initialize the adapter and recyclerview inside the onCreateView method, onActivityCreated, and onViewCreated method and none of them seem to be working.
Here's my fragment code:
private KidAdapter adapter;
private RecyclerView recyclerView;
Button button;
View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.uangsaku_menu_fragment, container, false);
button = view.findViewById(R.id.btn_add);
button.setOnClickListener(this);
recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
setUpRecyclerView();
return view;
}
#Override
public void onClick(View v) {
if(v.getId() == R.id.btn_add){
Intent intent = new Intent(getActivity(), Register.class);
startActivity(intent);
}
}
public void setUpRecyclerView(){
Query query = FirebaseDatabase.getInstance().getReference("kids");
FirebaseRecyclerOptions<kidData> options = new FirebaseRecyclerOptions.Builder<kidData>()
.setQuery(query, kidData.class)
.build();
adapter = new KidAdapter(options);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(adapter);
}
#Override
public void onStart() {
super.onStart();
if (adapter != null) {
adapter.startListening();
}
}
#Override
public void onStop() {
super.onStop();
if (adapter != null) {
adapter.stopListening();
}
}
}
The adapter class
public class KidAdapter extends FirebaseRecyclerAdapter<kidData, KidAdapter.KidViewHolder> {
public KidAdapter(#NonNull FirebaseRecyclerOptions<kidData> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull KidViewHolder holder, int position, #NonNull kidData model) {
holder.nama.setText(model.getKidName());
holder.balance.setText(model.getKidBalance());
holder.limit.setText("Limit: "+model.getKidLimit());
holder.spending.setText("Spending xxx.xxx");
}
#NonNull
#Override
public KidViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.kids_card,
viewGroup, false);
return new KidViewHolder(v);
}
public class KidViewHolder extends RecyclerView.ViewHolder {
TextView nama, balance, limit, spending;
public KidViewHolder(#NonNull View itemView) {
super(itemView);
nama = itemView.findViewById(R.id.tv_nama);
balance = itemView.findViewById(R.id.tv_balance);
limit = itemView.findViewById(R.id.tv_dailylimit);
spending = itemView.findViewById(R.id.tv_dailyspending);
}
}
}
The kidData model class
public class kidData {
String kidName, kidEmail, kidDoB, kidLimit, kidBalance;
public kidData(){
}
public kidData(String kidName, String kidEmail, String kidDoB, String kidLimit, String kidBalance) {
this.kidName = kidName;
this.kidEmail = kidEmail;
this.kidDoB = kidDoB;
this.kidLimit = kidLimit;
this.kidBalance = kidBalance;
}
public String getKidName() {
return kidName;
}
public String getKidEmail() {
return kidEmail;
}
public String getKidDoB() {
return kidDoB;
}
public String getKidLimit() {
return kidLimit;
}
public String getKidBalance() {
return kidBalance;
}
}
The problem in your code is the use of the following line of code:
recyclerView.setHasFixedSize(true);
And this is because when using the latest version of Firebase-UI library, there is no need to set the size of the RecyclerView as fixed. The solution for solving this problem is to simply remove/comment the above line of code. That's it!

FireBaseRecyclerView in FirebaseRecyclerView can not be applied to : (arguments)

I'm trying to retrieve data from Firebase to Recyclerview. I've already implement all other steps but now i'm getting error at the last stage when i'm implementing the adapter(FirebaseRecyclerAdapter).
My Fragment
public class Journal extends Fragment {
RecyclerView recyclerView;
DatabaseReference myref;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_journal,container,false);
myref= FirebaseDatabase.getInstance().getReference("/Journal");
recyclerView = (RecyclerView) v.findViewById(R.id.journal_rv);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
JournalEntry.class,
R.layout.journal_list_item,
JournalHolder.class,
myref) {
#Override
protected void onBindViewHolder(JournalHolder holder, int position, JournalEntry model) {
holder.setTitle(model.getEvent_title());
holder.setContent(model.getEvent_content());
holder.setSchool(model.getSchool_name());
holder.setDate(model.getDate());
holder.setStudents(model.getNumber_of_students());
holder.setSchoolIv(model.getImg_url());
}
#Override
public JournalHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}
};
return v;
}
public static class JournalHolder extends RecyclerView.ViewHolder{
TextView Jtitle , Jcontent,Jschool,Jstudents,jdate;
ImageView schoolIV;
public JournalHolder(View itemView) {
super(itemView);
Jtitle =(TextView)itemView.findViewById(R.id.journal_title);
Jcontent =(TextView)itemView.findViewById(R.id.event_content);
Jschool =(TextView)itemView.findViewById(R.id.journal_school);
Jstudents =(TextView)itemView.findViewById(R.id.journal_students);
jdate = (TextView)itemView.findViewById(R.id.journal_dates) ;
schoolIV = (ImageView)itemView.findViewById(R.id.journal_image);
}
public void setTitle(String title) {
Jtitle.setText(title);
}
public void setContent(String content) {
Jcontent.setText(content);
}
public void setSchool(String school) {
Jschool.setText(school);
}
public void setDate(String date) {
jdate.setText(date);
}
public void setStudents(String students) {
Jstudents.setText(students);
}
public void setSchoolIv(String schoolIv) {
Picasso.with(itemView.getContext())
.load(schoolIv)
.into(schoolIV);
}
}
}
This is what is shown as error
FireBaseRecyclerView in FirebaseRecyclerView can not be applied to :
JournalEntry.class (java...consti.last.database.JournalEntry>)
R.layout.journal_list_item (int)
BlogViewHolder.class (java...consti.last.Journal.BlogViewHolder>)
myref (com...firebase.database.DatabaseReference)
Please help me. I tried all the methods but nothing works.
Or if you have any advice...thank you in advance.
PS : I'm using Fragments
under Activity declaration write:-
private FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter;
then inside onCreateView():
adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
JournalEntry.class,
R.layout.journal_list_item,
JournalHolder.class,
myref) { //be sure that these classes and parameters are correct..
above return v;:
recyclerView.setAdapter(adapter);
Use this method instead of onBindViewHolder:
#Override
protected void populateViewHolder(JournalHolder holder,JournalEntry model, int position) {
Be sure you have all the correct methods in the model class JournalEntry.class and holder class JournalHolder.class and that its the right location and right layout.
I finally found solution here:Firebase RecyclerView
I had the same problem.
In this version FirebaseResycleView use the following:
Query query = FirebaseDatabase.getInstance()
.getReference(); // you can add child as .child("child_name");
FirebaseRecyclerOptions<JournalEntry> options = new FirebaseRecyclerOptions.Builder<JournalEntry>()
.setQuery(query, JournalEntry.class)
.build();
FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
options) {
#Override
protected void onBindViewHolder(JournalHolder holder, int position, JournalEntry model) {
holder.setTitle(model.getEvent_title());
holder.setContent(model.getEvent_content());
holder.setSchool(model.getSchool_name());
holder.setDate(model.getDate());
holder.setStudents(model.getNumber_of_students());
holder.setSchoolIv(model.getImg_url());
}
#Override
public JournalHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.journal_list_item, parent, false);
return new JournalHolder(view);
}
};
And after don't forget:
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
adapter.startListening();

Butterknife not loading layout after adapter has been modified

I don't know what I am doing wrong here.
My Adapter looks like this:
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.ViewHolder> {
private final List<String> sourceData;
public TestAdapter(List<String> sourceData) {
this.sourceData = sourceData;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.spanitem_goods, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
String item = sourceData.get(position);
holder.textView.setText(item);
}
#Override
public int getItemCount() {
return sourceData.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
#BindView(R.id.spanitem_imageView)
ImageView imageView;
#BindView(R.id.spanitem_textView)
TextView textView;
public ViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
}
}
}
Somewhere in my Activity I am transacting different Fragments which have all the same above adapter. It works fine with swapping them in and out, but as soon as I call this on adapter
adapter.notifyItemInserted(position);
and swap the fragments in and out again, it does not load any layout anymore. Just a blank page and this only happens when I call the above method.
My abstract BaseFragment has this in onCreateView
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG, "... onCreateView() called");
View v = inflater.inflate(getLayoutResourceId(), container, false);
unbinder = ButterKnife.bind(this, v);
ButterKnife.setDebug(true);
return v;
}
#Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
Log.d(TAG, "... onDestroyView() called");
}
Well I found the issue. Seems pretty unrelated to the entry question, but I might help someone else.
I was using the Observer pattern and had the update method in a non-ui thread running. Seems like that was the problem, since the RecyclerView never got updated unless I scrolled manually.
#Override
public void update(final String epc) {
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
sourceData.add(epc);
notifyDataSourceChanged(sourceData.size() - 1);
}
});
}

Set onclicklistener in recyclerview

My adaptor class:
public class Adaptor extends RecyclerView.Adapter<Adaptor.Holder>{
private ArrayList<Winkel> winkels;
private LayoutInflater inflater;
private ImageView icon;
private ItemCLickCallback itemCLickCallback;
public interface ItemCLickCallback {
void onItemClick(int p);
void onSecItemClick(int p);
}
public void setItemCLickCallback(final ItemCLickCallback itemCLickCallback1){
;this.itemCLickCallback = itemCLickCallback;
}
public Adaptor (ArrayList<Winkel> winkels,Context c){
this.inflater = LayoutInflater.from(c);
this.winkels = winkels;
}
#Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.list_item,parent,false);
return new Holder(view);
}
#Override
public void onBindViewHolder(Holder holder, int position) {
Winkel winkel = winkels.get(position);
holder.title.setText(winkel.getNaam());
if (winkel.isFavourtite()){
holder.icon.setImageResource(R.drawable.ic_star_black_18dp);
}
else{
holder.icon.setImageResource(R.drawable.ic_star_border_black_18dp);
}
}
#Override
public int getItemCount() {
return winkels.size();
}
class Holder extends RecyclerView.ViewHolder implements View.OnClickListener{
private TextView title;
private View container;
private ImageView icon;
public Holder(View itemView) {
super(itemView);
title = (TextView)itemView.findViewById(R.id.lbl_item_text);
container = itemView.findViewById(R.id.cont_item_root);
icon = (ImageView) itemView.findViewById(R.id.im_item_icon_secondary);
icon.setOnClickListener(this);
container.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if(v.getId()==R.id.cont_item_root){
itemCLickCallback.onItemClick(getAdapterPosition());
}
else{
itemCLickCallback.onSecItemClick(getAdapterPosition());
}
}
}
}
#Override
public void onClick(View v) {
}
}
}
Code where it gets implemented (my issue is here at adaptor.setItemClickCallback(context)
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Adaptor adaptor = new Adaptor(winkels,context);
recyclerview.setLayoutManager(new LinearLayoutManager(context));
recyclerview.addItemDecoration(new VerticalSpace(30));
recyclerview.setAdapter(adaptor);
adaptor.setItemCLickCallback(context);
}
Called from fragment overview:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_overview, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycle);
ODKortrijkWebservice webs = new ODKortrijkWebservice(this.getActivity(),mRecyclerView);
webs.execute();
return view;
}
How do I set the context for ItemCLickCallback(this)? It should be context (at least I think so?) because that's what gets passed from the fragment but I can't seem to figure out how to get this to work, so some help would be appreciated. Basically I want to add onclicklisteners for every item in my recyclerview, and the recyclerview is created by using data from a webservice, hence why the adaptor class is called from the class where I get the data from the web service, which gets excecuted in my fragment. Thank you.
I recommend you to make ODKortrijkWebservice.Callback like following.
In your ODKortrijkWebservice:
public class ODKortrijkWebservice extends AsyncTask<...> {
private Callback mCallback;
public interface Callback {
void onSuccess(ArrayList<Winkel> winkels);
}
public ODKortrijkWebservice(Context context, Callback callback) {
...
mCallback = callback;
...
}
#Override
protected void onPostExecute(Void aVoid) {
...
mCallback.onSuccess(winkels);
}
}
In your Fragment:
public class YourFragment extends Fragment implements ODKortrijkWebservice.Callback, Adaptor.ItemCLickCallback {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_overview, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycle);
ODKortrijkWebservice webs = new ODKortrijkWebservice(this.getActivity(), this);
webs.execute();
return view;
}
#Override
public void onSuccess(ArrayList<Winkel> winkels) {
Adaptor adaptor = new Adaptor(winkels, getContext());
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerView.addItemDecoration(new VerticalSpace(30));
mRecyclerView.setAdapter(adaptor);
adaptor.setItemCLickCallback(this);
}
#Override
public void onItemClick(int p) {
}
#Override
public void onSecItemClick(int p) {
}
}
Here,
You need to create one interface at RecycleView.Adapter<>
private static OnItemClickListener listener;
// Define the listener interface
public interface OnItemClickListener {
void onItemClick(View itemView, int position);
}
// Define the method that allows the parent activity or fragment to define the listener
public void setOnItemClickListener(OnItemClickListener listener) {
this.listener = listener;
}
send require details with interface method
public class ViewHolder extends RecyclerView.ViewHolder{
TextView header_title;
public ViewHolder(final View itemView) {
super(itemView);
txt_country_name = (TextView)itemView.findViewById(R.id.header_title);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Triggers click upwards to the adapter on click
if (listener != null)
listener.onItemClick(itemView, getLayoutPosition());
}
});
}
}
call adapter listener
ListAdapter listAdapter;
listAdapter.setOnItemClickListener(new listAdapter.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
Toast.makeText(getActivity(), position+ " was clicked!", Toast.LENGTH_SHORT).show();
}
});

Categories