The onListItemClick is not working. I am trying to store the values selected in the listview and pass it on to the mainactivity.
How can I get the selected Items positions and pass it on to the Main Activity?
Please suggest and thank you for the help.
Here is my code:
public static class ListViewFragment extends Fragment {
public static final String ARG_PLANET_NUMBER = "planet_number";
//FragmentActivity listener;
private ListView myListView;
private EditText editsearch;
private CheckBox selectAll;
private ArrayList<String> SelectedFilter1;
private ArrayList<String> CheckedFitlers;
ArrayAdapter<String> adapter_list;
public ListViewFragment() {
// Empty constructor required for fragment subclasses
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
SelectedFilter1=getArguments().getStringArrayList("ArrayList");
adapter_list = new ArrayAdapter<String>(this.getActivity(),
android.R.layout.simple_list_item_multiple_choice,SelectedFilter1);
adapter_list.notifyDataSetChanged();
myListView.setAdapter(adapter_list);
myListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
myListView.setTextFilterEnabled(true);
editsearch.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
adapter_list.getFilter().filter(text);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
selectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
Log.i("CheckBOX","Is Checked:"+isChecked);
if(isChecked)
{
for ( int i=0; i< myListView.getCount(); i++ )
myListView.setItemChecked(i, true);
}else
{
for ( int i=0; i< myListView.getCount(); i++ )
myListView.setItemChecked(i, false);
}
}
}
);
}
public void onListItemClick(ListView l, View v, int position, long id) {
//showDetails(position);
Log.i("Item Clicked in the Listview","Item Clicked in the listview: "+position);
//Toast.makeText(getActivity(), "Item Clicked in the listview: "+position, 3000).show();
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_list_view, container, false);
myListView=(ListView) rootView.findViewById(R.id.listView_brand);
editsearch = (EditText) rootView.findViewById(R.id.search);
selectAll=(CheckBox) rootView.findViewById(R.id.checkBox1);
//myListView.setFocusable(false);
// myListView.setClickable(false);
selectAll.setFocusable(false);
// rootView.setFocusable(false)
return rootView;
}
}
The XML:
<RelativeLayout 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: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="test.dsi.decathnavigation.Brand_list" >
<ListView
android:id="@+id/listView_brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/search"
android:fastScrollAlwaysVisible="false"
android:fastScrollEnabled="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollingCache="true"
android:smoothScrollbar="false" >
</ListView>
<EditText
android:id="@+id/search"
android:layout_width="450dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listView_brand"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="Type to search" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/search"
android:text="Select All" />
</RelativeLayout>