I have a listview in a fragment here is my current code for it:
public static class AllSectionFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public AllSectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_tasks_all,
container, false);
// /////////////////////////////////////////////////////////////////
// Set up all components here:: ie text views , buttons lists etc.//
// that correspond to the layout fragment xml file //
////////////////////////////////////////////////////////////////////
TextView dummyTextView = (TextView) rootView
.findViewById(R.id.fragment_tasks_all_textView);
dummyTextView.setText(Integer.toString(getArguments().getInt(
ARG_SECTION_NUMBER)));
ArrayList<String> arrayList = new ArrayList<String>();
ListView allList = (ListView) rootView
.findViewById(R.id.fragment_tasks_all_list);
MyCustomAdapter mAdapter = new MyCustomAdapter(getActivity(),
arrayList); // Class to populate a ListView with an
// ArrayList
allList.setAdapter(mAdapter);
// Populate array list
for (int i = 0; i < 5; i++) {
arrayList.add(" All Task " + i);
}
mAdapter.notifyDataSetChanged();
return rootView;
}
public void onListItemClick(ListView l, View v, int position, long id) {
System.out.println("pos: "+ position);
}
}
and my layout.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TasksActivity$DummySectionFragment" >
<TextView
android:id="@+id/fragment_tasks_all_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/fragment_tasks_all_list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.41"
android:cacheColorHint="#00000000"
android:clickable="true"
android:listSelector="@android:color/transparent"
android:transcriptMode="alwaysScroll" >
</ListView>
First of all. how can i make it so that i can click on an item in the list,
and second of all how do i add the onclick listener for it.
allList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> p, View view, int position, long id) { System.out.println("pos: " + position); } });but now when i click on the list view on the device it doesn't high light it or show it as being clicked. but my log cat shows that i clicked it.