getView on extended ArrayAdapter always has position 0 - android

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;
}
}

Related

custom listview repeat last row

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();
}
}
}

Drawing a listview through ListItem.add returns always a position = 0

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);
}

Update ListView's data

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?

How to create a Multilevel list using listview

The following is my Json data from database, i want to list the interest_name in a list(only if visible is true). List must be multilevel. I parsed the json file using Gson library. But i have no idea regarding how to make a multilevel list using listview.
{"interest_id":0,"interest_name":"ROOT","visible":false,"children":
[{"interest_id":1,"interest_name":"Sports","visible":true,"children":[{"interest_id":2,"interest_name":"Archery","visible":true,"children":[]},{"interest_id":3,"interest_name":"Bow Hunting","visible":true,"children":[]}]},{"interest_id":100,"interest_name":"Contry","visible":true,"children":[{"interest_id":101,"interest_name":"Afghanistan","visible":true,"children":[]},{"interest_id":102,"interest_name":"Akrotiri","visible":true,"children":[]}]},{"interest_id":1000,"interest_name":"Education","visible":true,"children":[]},{"interest_id":1200,"interest_name":"Entertainment","visible":true,"children":[]},{"interest_id":1400,"interest_name":"Books","visible":true,"children":[]},{"interest_id":1600,"interest_name":"Services","visible":true,"children":[]},{"interest_id":1800,"interest_name":"Fitness","visible":true,"children":[]},{"interest_id":2000,"interest_name":"Fashion","visible":true,"children":[]},{"interest_id":99999,"interest_name":"Near Me","visible":false,"children":[]}]}
My code:
Home.java
Intent intent = new Intent( Home.this,InterestAddList.class);
startActivity(intent);
finish();
InterestAddList.java
public class InterestAddList extends Activity {
ListView intrestListView;
OneOnOneListAdapter adapter;
List<String> intrestList;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intrest_add);
intrestListView = (ListView) findViewById(R.id.InterestList);
//Service Called For retrieving Data
retrieveList();
}
public void retrieveList() {
intrestList = new ArrayList<String>();
StringBuilder urlc = new StringBuilder(urlPrefix + "gai");
String url=urlc.toString();
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
String result = ServiceClient.getInstance().getResponse(url);
InterestNode ni=gson.fromJson(result, InterestNode.class);
//for(int i=0;i<ni.length;i++){
//Log.e("ni", ni.getInterestName());
//Log.e("ni", String.valueOf(ni.getInterestId()));
/* how to display interest name */
intrestList.add(ni.getInterestName());
}
adapter = new OneOnOneListAdapter(InterestAddList.this,R.layout.intrest_add_row,intrestList);
intrestListView.setAdapter(adapter);
}
private class OneOnOneListAdapter extends ArrayAdapter {
public OneOnOneListAdapter(Context context, int textViewResourceId,
List objects) {
super(context, textViewResourceId, objects);
}
#Override
public long getItemId(int position) {
return super.getItemId(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
final int aposition=position;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.intrest_add_row, null);
}
TextView intrestText =(TextView)v.findViewById(R.id.IntrestText);
intrestText.setText(intrestList.get(aposition).toString());
v.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
System.out.println("OnItem CLicked");
Toast.makeText(InterestAddList.this,"Position clicked:"+intrestList.get(aposition).toString(),Toast.LENGTH_SHORT).show();
Intent i = new Intent(InterestAddList.this,SubIntrestAddList.class);
i.putExtra("position", aposition);
startActivityForResult(i,1);
}
});
return v;
}
}}
InterestNode.java
public class InterestNode {
#SerializedName("interest_id")
int interestId;
#SerializedName("interest_name")
String interestName;
#SerializedName("visible")
boolean isVisible;
transient InterestNode parent;
#SerializedName("children")
List<InterestNode> childList = new ArrayList<InterestNode>();
public List<InterestNode> getChildren(){
return new ArrayList<InterestNode>(childList);
}
public int getInterestId() {
return interestId;
}
public String getInterestName() {
return interestName;
}
public InterestNode getParent() {
return parent;
}
public boolean isVisible() {
return isVisible;
}
public void addChild(InterestNode intNode){
childList.add(intNode);
}
public void setInterestId(int interestId) {
this.interestId = interestId;
}
public void setInterestName(String interestName) {
this.interestName = interestName;
}
public void setParent(InterestNode parent) {
this.parent = parent;
}
public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
}
}
It better to use Expandable ListView to add multilevel list, instead. But you want using listview then follow below nice tutorial here step by step three level listiview is achieved.
Android Multilevel ListView Tutorial
hope it helps you!

Custom arrayAdapter with listFragment

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.

Categories

Resources