hi i want to get values from database and show in listview
i get 6 value from database and send it to adapter but all 6 row is last item to send to adapter
when i add
ViewHolder holder;
android studio after alt + enter change to
RecyclerView.ViewHolder holder;
i read this post's but can not fix problem
Rows being repeated in ListView
Duplicated entries in ListView
Android Listview row repeating item
List item repeating in android customized listview
I know this question is duplicate but can not fix it
Thanks in advance
my adapter :
public class lim_sms_adapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<lim_sms> lim_smsItems;
public lim_sms_adapter (Activity activity, List<lim_sms> lim_smsItems) {
this.activity = activity;
this.lim_smsItems = lim_smsItems;
}
#Override
public int getCount() {
return lim_smsItems.size();
}
#Override
public Object getItem(int location) {
return lim_smsItems.get(location);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public int getViewTypeCount() {
return getCount();
}
#Override
public int getItemViewType(int position) {
return position;
}
#SuppressLint("SetTextI18n")
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.row_lim_sms, null);
TextView number = (TextView) convertView.findViewById(R.id.row_lim_sms_txt_number);
lim_sms m = lim_smsItems.get(position);
number.setText(m.getSms_number());
return convertView;
}
}
my class seter and geter :
public class lim_sms {
String sms_number;
public lim_sms(String sms_number) {
this.sms_number = sms_number;
}
public lim_sms() {
}
public String getSms_number() {
return sms_number;
}
public void setSms_number(String sms_number) {
this.sms_number = sms_number;
}
}
my activity :
public class list_limit_sms extends AppCompatActivity {
private List<lim_sms> limit_sms = new ArrayList<lim_sms>();
private lim_sms_adapter adapter;
private sms_database sms_db = new sms_database(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_limit_sms);
ListView listView = (ListView) findViewById(R.id.list_lim_sms);
adapter = new lim_sms_adapter(this, limit_sms);
listView.setAdapter(adapter);
lim_sms cy = new lim_sms();
List<sms_class> sms_list = sms_db.getAllContacts();
for (sms_class ss : sms_list) {
//String log = "Id: "+ss.getId()+" ,num: " + ss.getNum() + " ,type: " + ss.getType();
//Toast.makeText(this, ""+log, Toast.LENGTH_LONG).show();
cy.setSms_number(ss.getNum());
Toast.makeText(this, ""+ss.getNum(), Toast.LENGTH_SHORT).show();
limit_sms.add(cy);
adapter.notifyDataSetChanged();
}
}
}
Related
I have an array of 3 elements which I try to draw in a listview. The issue is that it only draws the first entry because getView always returns a position = 0.
Why is that? What do I do wrong?
my main java (fragment):
public class PSGlobalFragment extends Fragment {
List<PSGitem> listPSGitem;
ListView list;
PSGadaptater psgAdapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.psglobal, container, false);
}
#Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String ip;
listPSGitem = new ArrayList<>();
psgAdapter = new PSGadaptater(getActivity(), listPSGitem);
listPSGitem.clear();
StoreDevDiscovery store = new StoreDevDiscovery();
// this is where I store the data
int count = store.getMax();
for(int i=0;i<count;i++){
ip = store.getIPDiscovery(i);
PSGitem item = new PSGitem();
item.setIp(ip);
listPSGitem.add(item);
list.setAdapter(psgAdapter);
}
}
and my adapter:
public class PSGadaptater extends BaseAdapter {
private int size = 0;
private List<PSGitem> listIp;
private LayoutInflater layoutInflater;
Context context;
public PSGadaptater(Context c, List<PSGitem> objects) {
context = c;
listIp = objects;
layoutInflater = LayoutInflater.from(context);
}
#Override
public void notifyDataSetChanged() {
size = listIp.size();
super.notifyDataSetChanged();
}
#Override
public int getCount() {
return listIp.size();
}
public Object getItem(int position) {
return listIp.get(position);
}
public long getItemId(int position) {
return position;
}
private class ViewIPHolder {
TextView ip_psg;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewIPHolder viewHolder;
if(convertView == null) {
viewHolder = new ViewIPHolder();
convertView = layoutInflater.inflate(R.layout.listview_item_psg, null);
viewHolder.ip_psg = (TextView) convertView.findViewById(R.id.ipaddr_psg);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewIPHolder) convertView.getTag();
}
viewHolder.ip_psg.setText(listIp.get(position).getIpaddr());
// position always = 0 this is my issue
return convertView;
}
}
and the PSCitem.java:
public class PSGitem {
private String ip1;
public String getIp(){
return ip1;
}
public void setIp(String ip){
ip1 = ip;
}
}
The problem is that you are creating your Adapter from an empty set of items:
listPSGitem = new ArrayList<>();
psgAdapter = new PSGadaptater(getActivity(), listPSGitem);
If you wish to add items to the adapter later, you should add the items to the adapter listIp list variable, and then let the adapter know about this change with notifyDataSetChanged() method.
Change your onActivityCreated method like below.
#Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String ip;
listPSGitem = new ArrayList<>();
listPSGitem.clear();
StoreDevDiscovery store = new StoreDevDiscovery();
// this is where I store the data
int count = store.getMax();
for(int i=0;i<count;i++){
ip = store.getIPDiscovery(i);
PSGitem item = new PSGitem();
item.setIp(ip);
listPSGitem.add(item);
}
psgAdapter = new PSGadaptater(getActivity(), listPSGitem);
list.setAdapter(psgAdapter);
}
I used to create a custom adapter which is based upon BaseAdapter class, not ArrayAdapter.
But here is an issue, when I try to populate my adapter with new data(whatever it is), my AdapterView represents more items, than it supposed to have.
Suppose we have an Activity, ListFragment and custom Adapter.
Implementation of an Adapter:
public class ContactAdapter extends BaseAdapter {
private List<Entry<String,String>> mDataModel;
private LayoutInflater mInflater;
private boolean[] isChecked;
private int mResourceId;
private static class ViewHolder {
private TextView adapterText;
private TextView adapterDate;
}
public ContactAdapter(Context context,int mResourceId) {
this(context, mResourceId,new ArrayList<Entry<String,String>>());
}
public ContactAdapter(Context context, int mResourceId,List<Entry<String,String>> mDataModel) {
this.mInflater = LayoutInflater.from(context);
this.mResourceId = mResourceId;
this.mDataModel = mDataModel;
this.isChecked = new boolean[mDataModel.size()];
}
#Override
public int getCount() {
return mDataModel.size();
}
#Override
public Entry<String,String> getItem(int position) {
return mDataModel.get(position);
}
public void selectItem(int position) {
isChecked[position] = !isChecked[position];
}
public void add(final Entry<String,String> entry) {
mDataModel.add(entry);
if(mDataModel.size()>isChecked.length) {
isChecked = Arrays.copyOf(isChecked, isChecked.length / 2 +
mDataModel.size());
}
notifyDataSetChanged();
}
public void unCheckItems() {
for (int index = 0; index < mDataModel.size(); index++)
isChecked[index] = false;
}
public void removeItem() {
for(int index=0;index<mDataModel.size();index++) {
if (isChecked[index])
mDataModel.remove(index);
}
notifyDataSetChanged();
}
#Override
public long getItemId(int position) {
return mDataModel.get(position).hashCode();
}
#Override
public View getView(int position,View convertView, ViewGroup parentGroup) {
ViewHolder holder;
if(convertView==null) {
convertView=mInflater.inflate(mResourceId,parentGroup,false);
holder=new ViewHolder();
holder.adapterDate=(TextView)(convertView.findViewById(R.id.adapterDate));
holder.adapterText=(TextView)(convertView.findViewById(R.id.adapterText));
convertView.setTag(holder);
}
else
holder=(ViewHolder)(convertView.getTag());
holder.adapterDate.setText(mDataModel.get(position).getValue());
holder.adapterText.setText(mDataModel.get(position).getKey());
convertView.setSelected(isChecked[position]);
return convertView;
}
}
Also I have a usual ListFragment's implementation with additional method addTo(...), in order to add rows to ListView.Data comes from an Activity.
Here is the method, which I call within an Activity to send a data to ListFragment:
public void addToContact(View view) {
String contact = mContact.getText().toString();
if(!contact.isEmpty()) {
if (contactFragment == null) {
contactFragment = (ContactFragment) getSupportFragmentManager().findFragmentByTag(BundleKey.CONTACT_FRAGMENT);
}
Calendar calendar = Calendar.getInstance();
final Entry<String, String> entry = new Entry<>(contact,
calendar.get(Calendar.MONTH) + "/" + calendar.get(Calendar.DAY_OF_MONTH) + "/"
+ calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE));
contactFragment.addEntry(entry);
}
mContact.getText().clear();
Toast.makeText(this,(contact.isEmpty()?
"Enter contact":"Contact has been added"),Toast.LENGTH_LONG).show();
}
So, when I add any new item, my ListView shows two similar items instead of one.Do you know how to fix it?
I have created a class PickedDropsAdapter that extends ArrayAdapter for a listView that lists Objects from a List
Adding and removing basically works fine except that position in getView is always 0 and I just can't figure out, why.
I found a few similar question but none of the answers was really helping
Maybe important to mention is that listView is in a Fragment which again is in a ViewPager with two pages.
PickedDropsAdapter.java
public class PickedDropsAdapter extends ArrayAdapter {
private LayoutInflater myInflater;
private List<PickedDrop> pickedList;
public PickedDropsAdapter(Context context, int resource, List objects){
super(context, resource, objects);
myInflater = LayoutInflater.from(context);
setData(objects);
}
public void setData(List list){
this.pickedList = list;
}
#Override
public int getPosition(Object item) {
return super.getPosition(item);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView profileName;
if (convertView == null) {
convertView = myInflater.inflate(R.layout.picked_drop, null);
profileName = (TextView)convertView.findViewById(R.id.profileName);
Log.i("TAG", "Name in adapter: " + pickedList.get(position).name);
Log.i("TAG", "Postion in adapter: " + position);
profileName.setText(pickedList.get(position).name);
pickedList.get(position).makeActive(convertView);
}
return convertView;
}
}
PickedDrop
public class PickedDrop extends Fragment {
int id, listLoc;
String name;
RelativeLayout pickedLayout;
PickedDropsFrag parentFrag = null;
public static PickedDrop newInstance(String nameParam, int idParam) {
final PickedDrop fragment = new PickedDrop();
fragment.name = nameParam;
Log.i("TAG", "Drop name: " + fragment.name);
fragment.id = idParam;
return fragment;
}
public PickedDrop() {
// Required empty public constructor
}
public void openDrop(){
MainActivity mainActivity = (MainActivity)parentFrag.getActivity();
mainActivity.openDrop(this);
}
public void openDrop(int i){
listLoc = i;
MainActivity mainActivity = (MainActivity)parentFrag.getActivity();
mainActivity.openDrop(this);
}
public void makeActive(View convertView){
pickedLayout = (RelativeLayout)convertView.findViewById(R.id.pickedLayout);
}
}
Part of PickedDropsFrag (The fragment that contains the listView)
public class PickedDropsFrag extends Fragment {
private OnFragmentInteractionListener mListener;
PickedDropsAdapter pickedAdapter;
ListView pickedListView;
List<PickedDrop> pickedList;
public PickedDropsFrag() {
// Required empty public constructor
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
pickedListView = (ListView)getView().findViewById(R.id.pickedListView);
pickedListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
PickedDrop drop = (PickedDrop) adapterView.getItemAtPosition(i);
drop.openDrop(i);
}
});
pickedList = new ArrayList<>();
pickedAdapter = new PickedDropsAdapter(
getActivity(),
R.layout.picked_drop,
pickedList
);
pickedListView.setAdapter(pickedAdapter);
}
public void addToPicked(PickedDrop drop){
drop.parentFrag = this;
//pickedList.add(drop);
pickedAdapter.add(drop);
drop.listLoc = pickedList.size() - 1;
//pickedAdapter.notifyDataSetChanged();
drop.openDrop();
}
That should be everything important, I hope I didn't forget anything.
Update following methods in your Adapter:
public class PickedDropsAdapter extends ArrayAdapter {
#Override
public int getCount() {
return pickedList.size();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView profileName;
if (convertView == null) {
convertView = myInflater.inflate(R.layout.picked_drop, null);
}
profileName = (TextView)convertView.findViewById(R.id.profileName);
Log.i("TAG", "Name in adapter: " + pickedList.get(position).name);
Log.i("TAG", "Postion in adapter: " + position);
profileName.setText(pickedList.get(position).name);
pickedList.get(position).makeActive(convertView);
return convertView;
}
}
I have a TextView outside ListView and i need to add prices when the plus button (ie,quantity is incremented )in ListView is clicked.In my program i am not able to add prices when new position ListView button is clicked.I need to find the total price to be payed by the customer when plus button is clicked in ListView
public class ListAdapter1 extends BaseAdapter {
public int qty=1;
public ArrayList<Integer> quantity = new ArrayList<Integer>();
private TextView total;
private String[] listViewItems,prices,weight;
TypedArray images;
public static int pValue;
private Context context;
public static boolean t=false;
CustomButtonListener customButtonListener;
public void setTextView(TextView total)
{
this.total = total;
}
public ListAdapter1(Context context, String[] listViewItems, TypedArray images, String[] weight, String[] prices) {
this.context = context;
this.listViewItems = listViewItems;
this.images = images;
this.prices=prices;
this.weight=weight;
}
public void setCustomButtonListener(CustomButtonListener customButtonListner)
{
this.customButtonListener = customButtonListner;
}
#Override
public int getCount() {
return 5;
}
#Override
public String getItem(int position) {
return listViewItems[position];
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View row;
final ListViewHolder listViewHolder;
if(convertView == null)
{
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.product,parent,false);
listViewHolder = new ListViewHolder();
listViewHolder.tvProductName = (TextView) row.findViewById(R.id.tvProductName)
listViewHolder.tvPrices = (TextView) row.findViewById(R.id.tvProductPrice);
listViewHolder.btnPlus = (ImageButton) row.findViewById(R.id.ib_addnew);
listViewHolder.edTextQuantity = (EditText) row.findViewById(R.id.editTextQuantity);
listViewHolder.btnMinus = (ImageButton) row.findViewById(R.id.ib_remove);
row.setTag(listViewHolder);
}
else
{
row=convertView;
listViewHolder= (ListViewHolder) row.getTag();
}
try{
listViewHolder.edTextQuantity.setText(quantity.get(position) );
}catch(Exception e){
e.printStackTrace();
}
listViewHolder.btnMinus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(context, " " + position, Toast.LENGTH_SHORT).show();
int mValue = Integer.parseInt(listViewHolder.edTextQuantity.getText().toString());
if (mValue <=0) {
System.out.println("not valid");
mValue=0;
listViewHolder.edTextQuantity.setText("" +mValue);
}
else{
pValue=pValue/mValue;
mValue--;
pValue=pValue*mValue;
total.setText(String.valueOf(pValue));
System.out.println("mvalue after reducing-----------"+mValue);
System.out.println("pvalue-----------"+pValue);
listViewHolder.edTextQuantity.setText( "" +mValue );
}
}
});
listViewHolder.btnPlus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(context, " " + position, Toast.LENGTH_SHORT).show();
int mValue = Integer.parseInt(listViewHolder.edTextQuantity.getText().toString());
pValue=Integer.parseInt(listViewHolder.tvPrices.getText().toString());
mValue++;
listViewHolder.edTextQuantity.setText("" + mValue);
System.out.println("mValue after increment---" + mValue);
pValue=pValue*mValue;
System.out.println("pvalue-----------"+pValue);
total.setText(String.valueOf(pValue));
}
});
return row;
}
I need to get total price when any of the ListView button is clicked.
First you need to store value in HashMap<> when user click the plus and minus button.
Then sum the all values in HashMap.
For Example
try{
int sum = 0;
for(HashMap<String, String> map : arrayList) {
sum += Integer.parseInt(map.get("mark"));
}
} catch (Exception e) {
//Manage your exception
}
// sum has the value for the marks total.
System.out.println("Total Marks: "+sum);
Refere my previous answer Here
For that you need to create interface which notify in activity where you want that count.
put snippet in adapter to initialize interface and setter.
public interface IEvent {
void onItemChange(int count);
}
private IEvent iEvent;
//setter method for interface
public void setQuanityEvent(IEvent ievent) {
this.lastPageHandler = handler;
}
put this code in btnMinus.setOnClickListener
//if ievent interface variable register via set
if (ievent != null) {
//pValue is quality COUNT you want to send outside listview.
ievent.onItemChange(pValue);
}
activity code after creating adapter instance
//ListAdapter1 adapter = new ListAdapter1(your params);
adapter.setQuanityEvent(new ListAdapter1.IEvent() {
#Override
public void onItemChange(int count) {
}
}
});
I'm trying to make a ListFragment. I looked the Api Demo (FragmentLayout). it works on a simple example and now i want to apply it to my existing project.
Here is my code. I create inner classes (RecipeList & RecipeDetail) as in the Api Demo.
public class InfoActivity extends MenuActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info_fragment_layout);
// ...
}
public static class RecipeList extends ListFragment {
private int mCurrentSelectedItemIndex = -1;
private boolean mIsTablet = false;
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
accountData = new ArrayList<Account>();
new AccountSyncTask() {
#Override
public void onPostExecute(
final ArrayList<ArrayList<String>> result) {
// For each retrieved account
Bd.insert(retrievedAccount);
accountData.add(retrievedAccount);
}
accountListAdapter = new AccountListAdapter(
InfoActivity.this, R.layout.accountlist_detail,
accountData);
accountListAdapter = new AccountListAdapter(
activityContext, R.layout.accountlist_detail,
accountData);
setListAdapter(accountListAdapter);
}
}.execute(sessionName, null, "getAllObjectOnServer",
String.valueOf(nbRow));
if (savedInstanceState != null) {
mCurrentSelectedItemIndex = savedInstanceState.getInt(
"currentListIndex", -1);
}
// This is a tablet if this view exists
View recipeDetails = getActivity()
.findViewById(R.id.recipe_details);
mIsTablet = recipeDetails != null
&& recipeDetails.getVisibility() == View.VISIBLE;
if (mIsTablet) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
if (mIsTablet && mCurrentSelectedItemIndex != -1) {
showRecipeDetails();
}
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
mCurrentSelectedItemIndex = position;
showRecipeDetails();
}
private void showRecipeDetails() {
if (mIsTablet) {
// Set the list item as checked
getListView().setItemChecked(mCurrentSelectedItemIndex, true);
// Get the fragment instance
RecipeDetail details = (RecipeDetail) getFragmentManager()
.findFragmentById(R.id.recipe_details);
// Is the current visible recipe the same as the clicked? If so,
// there is no need to update
if (details == null
|| details.getRecipeIndex() != mCurrentSelectedItemIndex) {
details = RecipeDetail
.newInstance(mCurrentSelectedItemIndex);
FragmentTransaction ft = getFragmentManager()
.beginTransaction();
ft.replace(R.id.recipe_details, details);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
} else {
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("currentListIndex", mCurrentSelectedItemIndex);
}
}
public static class RecipeDetail extends Fragment {
private int mRecipeIndex;
public static RecipeDetail newInstance(int recipeIndex) {
// Create a new fragment instance
RecipeDetail detail = new RecipeDetail();
// Set the recipe index
detail.setRecipeIndex(recipeIndex);
return detail;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
View v = inflater
.inflate(R.layout.recipe_details, container, false);
//..
return v;
}
public int getRecipeIndex() {
return mRecipeIndex;
}
public void setRecipeIndex(int index) {
mRecipeIndex = index;
}
}
I have a custom ArrayAdapter (my items in the ListFragment contain 4 textViews and a clickable imageButton).
AccountListAdapter :
public class AccountListAdapter extends ArrayAdapter<Account> {
private final Context context;
private final int layoutResourceId;
private final ArrayList<Account> data;
public AccountListAdapter(Context context, int layoutResourceId,
ArrayList<Account> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
AccountHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
holder = new AccountHolder();
convertView.setClickable(true);
convertView.setFocusable(true);
holder.txtName = (TextView) convertView.findViewById(R.id.nom);
holder.txtId = (TextView) convertView.findViewById(R.id.id);
convertView.setTag(holder);
} else {
holder = (AccountHolder) convertView.getTag();
}
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.i("click", "index = " + position);
}
});
holder.txtName.setText(data.get(position).getName());
holder.txtId.setText(data.get(position).getId());
convertView.setBackgroundResource(R.drawable.list_selector);
ImageButton img = (ImageButton) convertView.findViewById(R.id.check);
img.setTag(position);
return convertView;
}
static class AccountHolder {
TextView txtName;
TextView txtId;
}
}
Problem :
When i click on an Item of the listFragment,
public void onListItemClick(ListView l, View v, int position, long id) {
mCurrentSelectedItemIndex = position;
Log.i("click", "here";
showRecipeDetails();
}
is not called but the listener on an item defined in AccountListAdapter works
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.i("click", "index = " + position);
}
});
Why is onListitemClick never called ?
Another question : is it a proper way to consume a web service in another thread in the onActivityCreated function of my ListFragment (in order to populate the list) ?
Thx in advance
EDIT = For the moment i made "showRecipeDetails" static and call it in the listener in my custom ArrayAdapter.
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
RecipeList.showRecipeDetails(position);
}}
I'm not satisfied with my solution, i'm interessed to any other solution
OnItemClickListeners must first be associated with the ListView you want to record clicks for. In your onActivityCreated(..) method, place getListView().setOnItemClickListener(this) somewhere and put implements OnItemClickListener after public static class RecipeList extends ListFragment.