---
title: "How to implement onItemClick method in FragmentList?"  
description: "How to implement onItemClick method in FragmentList?"  
author: "marcel ethan"  
published: 2013-05-30  
updated: 2013-05-30  
canonical: https://www.mindstick.com/forum/941/how-to-implement-onitemclick-method-in-fragmentlist  
category: "android"  
tags: ["android"]  
reading_time: 3 minutes  

---

# How to implement onItemClick method in FragmentList?

Hi Expert! \
I need [listView](https://www.mindstick.com/articles/12744/listview-in-android) in one tab fragment, so I implemented code from this example: http://geekswithblogs.net/bosuch/archive/2011/01/31/android---create-a-custom-multi-\
line-listview-bound-to-an.aspx. The list [shows up](https://answers.mindstick.com/qa/50405/apple-iphone-x-shows-up-liquid-detected-error-when-charging), when some [operation](https://www.mindstick.com/forum/33917/how-to-callback-operation-using-delegate-in-c-sharp) in MainActivity is completed, but I don't know how to do it clickable. I tried like is shown in this example, but it's not working, I think the problem is because I have fragment, this example is in MainActivity. Please, help!\
public class FragmentLogbook extends ListFragment {\
//handler for [passing data](https://www.mindstick.com/interview/34053/passing-data-into-components-in-knockout) through thread private Handler handler; //progress dialog private ProgressDialog progressDialog;\
private int progressBarStatus;\
SingletonLogbookPack mSingletonLogbookPack = SingletonLogbookPack.getInstance(); [ArrayList](https://www.mindstick.com/articles/11973/arraylist-class-in-c-sharp)<SearchResults> searchResults = GetSearchResults();\
MyCustomBaseAdapter mAdapter;\
// Create an empty adapter we will use to display the loaded data. //CustomArrayAdapter mAdapter = new CustomArrayAdapter(getActivity());\
\
@Override [public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); \
handler = new Handler(); startDownloadingLogbooks();\
} \
private void startDownloadingLogbooks() { progressDialog = new ProgressDialog(getActivity()); //progressDialog = ProgressDialog.show(getActivity(),"Loading Logbooks", "Please wait..."); progressDialog.setCancelable(false); progressDialog.setMessage("Loading Logbooks ..."); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setProgress(0); progressDialog.setMax(100); progressDialog.show();\
//reset [progress bar](https://www.mindstick.com/articles/12747/android-progress-bar) status progressBarStatus = 0;\
// start the time consuming task in a new thread Thread thread = new Thread() { public void run () { boolean p = ((MainActivity)getActivity()).mGpsColibri.mBinary.getLogbook(); while ( ((MainActivity)getActivity()).logbookFinished != true ) { progressBarStatus = (int) ((MainActivity)getActivity()).GetProgressValue(); progressDialog.setProgress(progressBarStatus); //in this time Progress dialog will be on screen } //set logbookFinished [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) from MainActivity to false ((MainActivity)getActivity()).logbookFinished = false; // this will handle the post task. // it will run when the time consuming task get finished handler.post(new Runnable() { @Override public void run() { // [Update your](https://answers.mindstick.com/qa/32325/how-often-should-you-update-your-cover-photo-for-your-company-page) UI or // do any Post job after the time consuming task // remember to dismiss the progress dialog here. updateUI(); progressDialog.dismiss(); } }); } };\
thread.start(); }\
private void updateUI() { //setListAdapter(mAdapter);\
mAdapter = new MyCustomBaseAdapter(getActivity(), searchResults); setListAdapter(mAdapter); }\
private ArrayList<SearchResults> GetSearchResults(){ ArrayList<SearchResults> results = new ArrayList<SearchResults>();\
SearchResults sr1 = new SearchResults(); sr1.setName("John Smith"); sr1.setCityState("Dallas, TX"); sr1.setPhone("214-555-1234"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Jane Doe"); sr1.setCityState("Atlanta, GA"); sr1.setPhone("469-555-2587"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Steve Young"); sr1.setCityState("Miami, FL"); sr1.setPhone("305-555-7895"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Fred Jones"); sr1.setCityState("[Las Vegas](https://www.mindstick.com/articles/43867/family-rv-parks-in-las-vegas-and-laughlin), NV"); sr1.setPhone("612-555-1234"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Bob Marsh"); sr1.setCityState("New York, NY"); sr1.setPhone("612-555-5678"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Harold Funk"); sr1.setCityState("Chicago, IL"); sr1.setPhone("612-555-8765"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Scott Dorf"); sr1.setCityState("Winslow, AZ"); sr1.setPhone("612-555-5432"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Mike Hail"); sr1.setCityState("Seattle, WA"); sr1.setPhone("612-555-0961"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Scott Dorf"); sr1.setCityState("Winslow, AZ"); sr1.setPhone("612-555-5432"); results.add(sr1);\
sr1 = new SearchResults(); sr1.setName("Mike Hail"); sr1.setCityState("Seattle, WA"); sr1.setPhone("612-555-0961"); results.add(sr1);\
return results; } }\
Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Hi Marcel,\
Try this after setting listview adapter\
getListView().setOnItemClickListener(new OnItemClickListener() {\
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Here you write auto - generated method stub }});\
It might be helpful for you.


---

Original Source: https://www.mindstick.com/forum/941/how-to-implement-onitemclick-method-in-fragmentlist

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
