I am new to android so please explain me in detail.
I have a class which extend ListFragment
public class ProfileFragment extends ListFragment{
/** An array of items to display in ArrayList */
String profile_list[] = new String[]{
"Personal Info",
"Account Info"
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
/** Creating array adapter to set data in listview */
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_1, profile_list);
/** Setting the array adapter to the listview */
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
super.onListItemClick(l, v, pos, id);
Toast.makeText(getActivity(), "Item " + pos + " was clicked", Toast.LENGTH_SHORT).show();
}
}
I want to add child list with some arrow indication (have child or not). I can not upload the image otherwise it will explain more clearly.
If I click on (Account Info) item two more rows come below the (Account Info) and disappear when click again on Account Info.
Please asnwer me in steps with code.
This is what you are looking for in particular, ExpandableListView
, to explain in brief, it helps to display views group wise, like in your case as you said, when you click a particular item it should expand and display further items beneath that view, this functionality is supported by ExpandableListView
by default, all you need to do is divide your data in groups, and plug them into adapter linking it to expandable listview and wollah you're done, check below link for more detail.
http://developer.android.com/reference/android/widget/ExpandableListView.html
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/