My onListItemClick is never call when i click on item, the class is extends fragment not listfragment, because i have other view items in this fragment which is not list, so how to implement onlistitemclick in class extends fragment?
class
public class MainFiles extends Fragment
{
ArrayList<String> items;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.files, container, false);
Button button_up = (Button) view.findViewById(R.id.button_up);
items = new ArrayList<String>();
MyAdapter adapter = new MyAdapter(getActivity(), R.layout.row, items);
ListView myList = (ListView) view.findViewById(R.id.list);
myList.setAdapter(adapter);
return view;
}
public void onListItemClick(ListView l, View v, int position, long id)
{
}
}
Explicitly add the OnItemClickListener to your ListView
myList.setOnItemClickListener(this);
You must also make sure that your Fragment implements the OnItemClickListener type:
public class MainFiles extends Fragment implements OnItemClickListener
Another way is to create a dedicated subclass of OnItemClickListener to pass to the ListView:
myList.setOnItemClickListener(new MyOnItemClickListener());
/* ... */
private class MyOnItemClickListener implements OnItemClickListener {
/* ... */
}
You forget to set the setOnItemClickListener
after myList.setAdapter(adapter); add this:
myList.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position,long id){
new File(items.get(position));
fileList(path.get(position));
showPath(current_path);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With