Hello,
I have a Fragment Which has a Custom ListView and All the ListView Events is Handled in Fragment Class Itself. Now When I Click On The ListView Item I Am Populating Same ListView Again Based On Condition. But If I Press Back Button I Want to again Fill ListView on Previous State.
Is this Possible? If yes how?
Below is the Code For Fragment With ListView
public class HomeFragment extends Fragment {
String CourseName[]={"Special Courses","Engineering","BScIT","BScCS"};
String UniversityEngArray[]={"Mumbai","Pune","Delhi","Rajasthan"};
String UniversityBScITArray[]={"Mumbai","Pune","Delhi","Rajasthan"};
Integer ImageId[]={
R.drawable.letters,
R.drawable.lettere,
R.drawable.letterb,
R.drawable.letterb
};
private ListView lv;
CustomList customList;
ArrayAdapter<String> adapter;
public HomeFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
customList = new CustomList(getActivity(), CourseName, ImageId);
lv = (ListView) rootView.findViewById(R.id.listView1);
lv.setAdapter(customList);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
if(CourseName[+position].toString().equalsIgnoreCase("Engineering")){
customList =new CustomList(getActivity(),UniversityEngArray,ImageId);
lv.setAdapter(customList);
}
else if(CourseName[+position].toString().equalsIgnoreCase("BScIT")){
customList =new CustomList(getActivity(),UniversityBScITArray,ImageId);
lv.setAdapter(customList);
}
}
});
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}