Android Contextual Action Bar not appearing after item selection - android-layout

In my android application, I am trying to show contextual action bar (CAB) in listview for item delete. The problem is that whenever an item is pressed for long, the item gets selected, but CAB doesn't appear. I have verified with so many tutorials, can't figure out what am I missing. Any help would be appreciated.
Adapter Class
public class DuasListAdapter extends ArrayAdapter<String>{
// class variables
private final Context context;// to save context
private final List<String> duas;// to save list of stores
LayoutInflater inflater;//
private SparseBooleanArray selectedItemsIds;
public DuasListAdapter(Context ctx,int resourceId, List<String> duasList) {
super(ctx, resourceId, duasList);
selectedItemsIds = new SparseBooleanArray();
context = ctx;// save context
duas = duasList;// save list of stores
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);// save inflater layout
}
*/
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.adapter_list_duas, null);
convertView.setTag(holder);
holder.duaIndex = position;
holder.background = (LinearLayout) convertView.findViewById(R.id.ll_duas_list);
holder.iv_duatype = (ImageView) convertView.findViewById(R.id.iv_duatype);
holder.tv_dua_arabic = (TextView) convertView.findViewById(R.id.tv_dua_arabic);
holder.tv_dua_no = (TextView) convertView.findViewById(R.id.dua_no);
}
else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
static class ViewHolder {
int duaIndex;
LinearLayout background;// background to display color for read and unread messages
ImageView iv_duatype;
TextView tv_dua_arabic;// title of message
TextView tv_dua_ref;// message by and message created on
TextView tv_dua_no;
/**
* #description constructor to save context and list of stores views
* #param v to refer the view
* #return
*/
}
public void remove(List<String> object){
duas.remove(object);
notifyDataSetChanged();
}
public List<String> getDuas(){
return duas;
}
public void toggleSelection(int position) {
selectView(position, !selectedItemsIds.get(position));
}
public void removeSelection() {
selectedItemsIds = new SparseBooleanArray();
notifyDataSetChanged();
}
public void selectView(int position, boolean value) {
if (value)
selectedItemsIds.put(position, value);
else
selectedItemsIds.delete(position);
notifyDataSetChanged();
}
public int getSelectedCount() {
return selectedItemsIds.size();
}
public SparseBooleanArray getSelectedIds() {
return selectedItemsIds;
}
}
Fragment Class
Context context;
LinearLayout ll_back_duas_list_header;
TextView ll_back_duas_list_header_title;
ListView lvDuaas;
public static DuasListAdapter duasAdapter;
ActionMode mAction;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = inflater.getContext();
View view = inflater.inflate(R.layout.fragment_list_duas, container, false);
ll_back_duas_list_header = (LinearLayout) view.findViewById(R.id.ll_back_duas_list_header);
ll_back_duas_list_header_title = (TextView) view.findViewById(R.id.ll_back_duas_list_header_title);
lvDuaas = (ListView) view.findViewById(R.id.lv_duas);
setHasOptionsMenu(true);
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
String verses = new SharedPreferencesSupplication().read(SingletonClass.keyListOfVerses, "a1");
String[] versesList = verses.split(",");
final ArrayList<String> duas = new ArrayList<String>();
for (int i = 0; i < versesList.length; i++) {
if (versesList[i].length() > 0)
duas.add(versesList[i]);
}
duasAdapter = new DuasListAdapter(context,R.layout.adapter_list_duas,duas);
lvDuaas.setAdapter(duasAdapter);
lvDuaas.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent,
View view, int position, long id) {
// TODO Auto-generated method stub
lvDuaas.setChoiceMode(lvDuaas.CHOICE_MODE_MULTIPLE);
lvDuaas.setItemChecked(position, true);
mAction = getActivity().startActionMode(modeCallBack);
view.setSelected(true);
return true;
}
});
super.onActivityCreated(savedInstanceState);
}
ActionMode.Callback modeCallBack = new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.getMenuInflater().inflate(R.menu.activity_main, menu);
return false;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode,
MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.delete:
// Calls getSelectedIds method from ListViewAdapter Class
SparseBooleanArray selected = duasAdapter
.getSelectedIds();
// Captures all selected ids with a loop
for (int i = (selected.size() - 1); i >= 0; i--) {
if (selected.valueAt(i)) {
String selecteditem = duasAdapter.getItem(selected.keyAt(i));
// Remove selected items following the ids
duasAdapter.remove(selecteditem);
}
}
// Close CAB
mode.finish();
return true;
default:
return false;
}
}
#Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
duasAdapter.removeSelection();
}
};
}
XML file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="#+id/delete"
android:title="#string/delete"
/>
</menu>

From looking at your code I can see the onCreateActionMode callback function returns false.
onCreateActionMode should return true if the action mode should be created, false if entering this mode should be aborted.
So when the user long clicks on the ListItem and the event is triggered it reaches onCreateActionMode and returns false. Telling it to abort. Hence no CAB menu appears. Try changing it to true and also adding in some logs to see if it ever makes it into the callback function.
This would be the change below:
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
Log.d("Test","In onCreateActionMode");
mode.getMenuInflater().inflate(R.menu.activity_main, menu);
return true;//code updated here
}
Android Link to reference : http://developer.android.com/reference/android/view/ActionMode.Callback.html#onCreateActionMode(android.view.ActionMode, android.view.Menu)

Related

NotifyDataSetChanged() not updating listview after closing alert dialog

In my adapter class I have created a alert dialog and added a update button to it which allows me to update the items on my list view, it updates my listview but only when I leave the page and return back to it, I have used notifydatasetchanged but it doesn't seem to work, I want it to update on the list view immediately after the dialog closing.
update button
viewHolder.btnDisplayUpdate.setText("Update");
viewHolder.btnDisplayUpdate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
updateCrime(crimes);
}
});
Update method
private void updateCrime(CrimesDelete crimes){
AlertDialog.Builder popupWindow = new AlertDialog.Builder(context);
LayoutInflater inflater = LayoutInflater.from(context);
View root = inflater.inflate(R.layout.dialog_update, null);
popupWindow.setView(root);
AlertDialog alertDialog = popupWindow.create();
alertDialog.show();
editLocation = (EditText)root.findViewById(R.id.editText_location);
editType = (EditText)root.findViewById(R.id.editText_type);
editDescription = (EditText)root.findViewById(R.id.editText_description);
editDate = (EditText)root.findViewById(R.id.textViewDate);
editTime = (EditText)root.findViewById(R.id.textViewTime);
Spinner spinner = (Spinner) root.findViewById(R.id.editText_rating);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
getContext(), R.array.rating, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
editRating = parent.getItemAtPosition(pos).toString();
if (pos==0){
editRating = null;
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
editLocation.setText(crimes.getLOCATION());
editType.setText(crimes.getTYPE());
editDescription.setText(crimes.getDESCRIPTION());
editDate.setText(crimes.getDATE());
editTime.setText(crimes.getTIME());
root.findViewById(R.id.btnAdd).setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
String location = editLocation.getText().toString().trim();
String type = editType.getText().toString().trim();
String description = editDescription.getText().toString().trim();
String date = editDate.getText().toString().trim();
String time = editTime.getText().toString().trim();
String rating = spinner.getSelectedItem().toString().trim();
DB_CRIME.updateDate(crimes.getID(), location, type, description, date, time, rating);
loadUpdatedCrimes();
alertDialog.dismiss();
}
});
}
private void loadUpdatedCrimes() {
notifyDataSetChanged();
Toast.makeText(getContext(), "Crime has been Updated" , Toast.LENGTH_SHORT).show();
}

how to Update ListView after deletion

Here I'm using Custom Adapter by implementing listAdapter to Support buttons in the list items. When i click the Delete button it deletes currect row. But i can't able to refresh this listView.
File Structure is MainActivity -> FragmentClass-> this Custom class for the listAdpater.
public class Category_ListView_Custom_Adapter extends BaseAdapter implements ListAdapter{
private Realm realm;
private ArrayList<String> list = new ArrayList<>();
private Context context;
public Category_ListView_Custom_Adapter(ArrayList<String> list, Context context){
this.list = list;
this.context = context;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int i) {
return list.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(final int i, View view, ViewGroup viewGroup) {
View view1 = view;
realm = Realm.getDefaultInstance();
if(view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.category_listview_row, null);
}
TextView listItemText = (TextView) view.findViewById(R.id.item);
listItemText.setText(list.get(i));
ImageView edit = (ImageView) view.findViewById(R.id.image);
ImageView delete = (ImageView) view.findViewById(R.id.delete);
edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// list.remove(i);
/// Toast.makeText(view.getContext(), "hey "+list.get(i).toString(), Toast.LENGTH_SHORT).show();
// notifyDataSetChanged();
Intent intent = new Intent(context, AddCategory.class);
intent.putExtra("category","expense");
intent.putExtra("subcategory", list.get(i));
context.startActivity(intent);
}
});
delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
RealmResults<Category> categorylist = realm.where(Category.class).equalTo("Id",i+1).and().equalTo("Subcategory",list.get(i)).findAll();
for (Category category : categorylist) {
realm.beginTransaction();
categorylist.deleteFirstFromRealm();
realm.commitTransaction();
try {
context.notifyAll();
}catch (Exception e){
Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
}
// Expense.call_resume
}
}
});
return view;
}
}
Please Help me. Thank you.
You are .removing from a wrong view. Try to make root List<> static and do Class.list.get(i).remove or something like that.
Also, try to hide a view inside your get view.

Creating a very custom list

I'm developping an application, and now, I don't know what to do next:
I have a list of elements, each element has some informations + an ID + a logo.
What I want to do is creating a list like in the picture
List
Of course, I want it in a single layer, with the logo, some informations, and a button to define an action; where I could use the ID of the selected item.
I did some research, may be I found some relative subjects, but none of what I want.
My list is a
ArrayList<ArrayList<String>>
filled by data from database.
Thank you
Here it is:
public class Avancee extends Activity {
// Log tag
private static final String TAG = MainActivity2.class.getSimpleName();
// Movies json url
private static final String url = "http://blabla.com/movie.json";
private ProgressDialog pDialog;
private List<Movie> movieList = new ArrayList<Movie>();
private ListView listView;
private CustomListAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
adapter = new CustomListAdapter(this, movieList);
listView.setAdapter(adapter);
pDialog = new ProgressDialog(this);
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
// changing action bar color
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#1b1b1b")));
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
//Log.d(TAG, response.toString());
hidePDialog();
String result = getIntent().getStringExtra("ITEM_EXTRAA");
System.out.println(result);
try{
JSONArray ja = new JSONArray(result);
for (int i = 0; i < ja.length(); i++) {
try {
JSONObject obj = ja.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("title"));
movie.setLocation(obj.getString("location_search_text"));
movie.setId(obj.getInt("id"));
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(movieReq);
}
#Override
public void onDestroy() {
super.onDestroy();
hidePDialog();
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
It's the "id" that I want to get in the OnClick event.
use this code
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Movie movie= movieList.get(position);
}
});
//here position will give you the id of listview cell so you can use it like
Movie movie= movieList.get(position);
then you can use it get all the data inside your moview object

can't call adapter.getFilter() after setup recyclerview with filterable

I've use Filterable inside my RecyclerView. What I wanted to do is, to filter the recyclerview from edittext. Below is my actual code.
public class NavDrawerAdapter_v2 extends RecyclerView.Adapter<NavDrawerAdapter_v2.ViewHolder> implements Filterable{
private static final int TYPE_ITEM = 0;
private ArrayList<String> menu_list;
private ArrayList<String> filtered_menu_list;
Context mContext;
public static class ViewHolder extends RecyclerView.ViewHolder {
int Holderid;
TextView shopName, shopLevel;
public ViewHolder(View itemView,int ViewType) {
super(itemView);
shopName = (TextView) itemView.findViewById(R.id.rowText);
shopLevel = (TextView) itemView.findViewById(R.id.rowLevel);
if(ViewType == TYPE_ITEM) {
Holderid = 0;
}
}
}
public NavDrawerAdapter_v2(Context mContext, ArrayList<String> menu_list){
this.menu_list = menu_list;
this.filtered_menu_list = menu_list;
this.mContext = mContext;
}
#Override
public NavDrawerAdapter_v2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_ITEM) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.drawer_item_row,parent,false); //Inflating the layout
return new ViewHolder(v,viewType);
}
return null;
}
#Override
public void onBindViewHolder(NavDrawerAdapter_v2.ViewHolder holder, int position) {
if (holder.Holderid == 0) {
String getShopName = menu_list.get(position).split("-")[0];
String getShopLevel = menu_list.get(position).split("-")[1];
holder.shopName.setText(getShopName);
holder.shopLevel.setText(getShopLevel);
}
}
#Override
public int getItemCount() {
return menu_list == null ? 0 : menu_list.size();
}
#Override
public long getItemId(int position) {
return super.getItemId(position);
}
#Override
public int getItemViewType(int position) {
return TYPE_ITEM;
}
public boolean okay(){
return true;
}
#Override
public Filter getFilter() {
return new UserFilter(this, menu_list);
}
private static class UserFilter extends Filter {
private final NavDrawerAdapter_v2 adapter;
private final ArrayList<String> originalList;
private final ArrayList<String> filteredList;
private UserFilter(NavDrawerAdapter_v2 adapter, ArrayList<String>originalList) {
super();
this.adapter = adapter;
this.originalList = new ArrayList<>(originalList);
this.filteredList = new ArrayList<>();
}
#Override
protected FilterResults performFiltering(CharSequence constraint) {
filteredList.clear();
final FilterResults results = new FilterResults();
if (constraint.length() == 0) {
filteredList.addAll(originalList);
} else {
final String filterPattern = constraint.toString().toLowerCase().trim();
for (String getValue : originalList) {
if (getValue.contains(filterPattern)) {
filteredList.add(getValue);
}
}
}
results.values = filteredList;
results.count = filteredList.size();
return results;
}
#Override
protected void publishResults(CharSequence constraint, FilterResults results) {
adapter.filtered_menu_list.clear();
adapter.filtered_menu_list.addAll((ArrayList<String>) results.values);
adapter.notifyDataSetChanged();
}
}
}
But, in my fragment. I can't call adapter.getFilter(). What is wrong here?
If you want EditText for searchView purposes, you need to add change listener for EditText, as explained in the link : android on Text Change Listener
When the text changed, you should call
adapter.getFilter().filter(newText);
Alternatively, you should try to implement searchview in action bar with recyclerView. Todo this, implement getFilter() method inside your RecyclerView adapter. You can use the getFilter() method implemented in the link https://stackoverflow.com/a/10532898/1308990 .
menu.xml:
<item android:id="#+id/menuSearch"
android:title="search"
android:icon = "#android:drawable/ic_menu_search"
app:actionViewClass = "android.support.v7.widget.SearchView"
app:showAsAction = "always|collapseActionView"></item>
Inside onCreateOptionsMenu() method, write following codes :
MenuItem item = menu.findItem(R.id.menuSearch);
//SearchView searchView = (SearchView) item.getActionView();
SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
//Called when the query text is changed by the user.
#Override
public boolean onQueryTextChange(String newText) {
Log.d("soda in MainActivity","onQueryTextChange method is called.");
mutfagimFragment.adapter.getFilter().filter(newText);
return false;
}
});
When the user changes the text, check whether the onQueryTextChange() method is called by monitoring the logs. If it is not called, try to put the above codes inside onPrepareOptionsMenu() method rather than onCreateOptionsMenu() method.
Following your example, I'm pretty sure you were assigning the object to a RecyclerView.Adapter variable instead of to a NavDrawerAdapter_v2 variable inside the Activity.
RecyclerView.Adapter adapter = new NavDrawerAdapter_v2(menuList);
instead of
NavDrawerAdapter_v2 adapter = new NavDrawerAdapter_v2(menuList);
NavDrawerAdapter_v2 extends from RecyclerView.Adapter but at the same time implements Filterable.
If you assign the object to a RecyclerView.Adapter variable you will still be able to call getItemCount(), onBindViewHolder() and onCreateViewHolder() (since they are abstract methods from RecyclerView.Adapter)
The bad part is that you won't be able to call getFilter() because it belongs to the Filterable interface.

Hashmap order inside the expandable listview varies from device to another

Now i'm making an application that it should display a list of courses in an expandable list view and when the user clicks on a child element it opens a new activity with the course details , everything works pretty fine but , when i tested the application through nexus the order of the courses was the same i put inside the hashmap and in the switch case statement but when i tested it through my galaxy not two here it came the disaster the orders in the list were scrambled so the click event got messed up when supposed to open course details for x it opens for y and so on ,,, what should i do ?
THIS IS THE MAIN
public class Courses extends ActionBarActivity {
HashMap<String,List<String>> Courses_castegory;
List<String> Courses_list;
ExpandableListView expandableListView;
MyCourseAdapter myCourseAdapter;
Intent detaledActivity;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_courses);
expandableListView = (ExpandableListView) findViewById(R.id.simple_expandable_list);
Courses_castegory = CourseProvider.getInfo();
Courses_list=new ArrayList<>(Courses_castegory.keySet());//get all the keys from the hashmap
myCourseAdapter = new MyCourseAdapter(this,Courses_castegory,Courses_list);
expandableListView.setAdapter(myCourseAdapter);
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getBaseContext(), Courses_list.get(groupPosition) + " is collapsed", Toast.LENGTH_SHORT).show();
}
});
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
//Toast.makeText(getBaseContext(),
//Courses_castegory.get(Courses_list.get(groupPosition)).get(childPosition)+" from "+Courses_list.get(groupPosition)+" is selected",Toast.LENGTH_SHORT).show();
switch(groupPosition) {
case 0:
switch (childPosition) {
case 0:
detaledActivity = new Intent(Courses.this, DetailedCouse.class);
startActivity(detaledActivity);
break;
}
}
return true;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_courses, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
THIS IS THE COURSE PROVIDER
public class CourseProvider {
public static HashMap<String,List<String>> getInfo(){
HashMap<String,List<String>>CourseDetails = new HashMap<String,List<String>>();
List<String> CourseType1 = new ArrayList<>();
CourseType1.add("English For Work");
List<String> CourseType2= new ArrayList<>();
CourseType2.add("General English For Work");
CourseType2.add("Intensive English For Work");
List<String> CourseType3 = new ArrayList<>();
CourseType3.add("English Academic Year");
CourseType3.add("English Academic Semester");
List<String> CourseType4 = new ArrayList<>();
CourseType4.add("IELTS Exam Preparation");
CourseType4.add("TOEFL Exam Preparation");
CourseType4.add("GMAT Exam Preparation");
CourseType4.add("GRE Exam Preparation");
List<String> CourseType5 = new ArrayList<>();
CourseType5.add("Young Learners");
List<String> CourseType6 = new ArrayList<>();
CourseType6.add("General English Language");
CourseType6.add("Intensive English Language");
CourseType6.add("30+");
CourseDetails.put("Learn English in Your Teacher's Home",CourseType1);
CourseDetails.put("English For Work",CourseType2);
CourseDetails.put("Academic Semester / Year",CourseType3);
CourseDetails.put("Exam Preparation Courses",CourseType4);
CourseDetails.put("Young Learners",CourseType5);
CourseDetails.put("Flexible Courses",CourseType6);
return CourseDetails;
}}
AND THIS IS THE COURSE ADAPTER
public class MyCourseAdapter extends BaseExpandableListAdapter {
private Context context;
private HashMap<String,List<String>>Courses_Category;
private List<String> Course_List ;
public MyCourseAdapter(Context context ,HashMap<String,List<String>>Courses_Category,List<String> Course_List) {
this.context=context;
this.Courses_Category=Courses_Category;
this.Course_List=Course_List;
}
#Override
public int getGroupCount() {
return Course_List.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return Courses_Category.get(Course_List.get(groupPosition)).size();
}
#Override
public Object getGroup(int groupPosition) {
return Course_List.get(groupPosition);
}
#Override
public Object getChild(int parent, int child) {
return Courses_Category.get(Course_List.get(parent)).get(child);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int parent, int child) {
return child;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String group_title = (String) getGroup(groupPosition);
if (convertView==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.parent_courses,parent,false);
}
TextView parent_textview = (TextView) convertView.findViewById(R.id.parent_text_view);
parent_textview.setTypeface(null, Typeface.BOLD);
parent_textview.setText(group_title);
return convertView;
}
#Override
public View getChildView(final int parentPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String child_title = (String) getChild(parentPosition,childPosition);
if (convertView==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=inflater.inflate(R.layout.child_courses,parent,false);
}
TextView child_textview = (TextView) convertView.findViewById(R.id.child_text_view);
child_textview.setText(child_title);
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void onGroupCollapsed(int groupPosition){
super.onGroupCollapsed(groupPosition);
}
public void onGroupExpanded(int groupPosition){
super.onGroupExpanded(groupPosition);
}}
//
Done using LinkedHashMapinstead of HashMap

Resources