I have three Android activities linked, i.e. App1Activity, FAQAdapter1 and DataProvider1.
App1Activity.java is the main activity where I have an expandable list and want to have a search view to work with the list. FAQAdapter1 gives command and pulls data from DataProvider1 where I have listed the items.
Here is my code for App1Activity and FAQAdapter1. I am not sharing code for DataProvider as it contains my personal data. You can consider it to be the source of any list items used by the other classes.
//App1Activity.java
package com.fys.abgsearchview; import android.app.Activity; import android.os.Bundle; import android.widget.ExpandableListView;
import java.util.ArrayList; import java.util.HashMap; import java.util.List;
public class App1Activity extends Activity { HashMap> FAQ_category; List FAQ_list; ExpandableListView Exp_list; FAQAdapter1 adapter; private int groupPosition; private int lastExpandedGroupPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Exp_list = (ExpandableListView) findViewById(R.id.exp_list);
FAQ_category = DataProvider1.getInfo();
FAQ_list = new ArrayList<String>(FAQ_category.keySet());
adapter = new FAQAdapter1(this, FAQ_category, FAQ_list);
Exp_list.setAdapter(adapter);
Exp_list.setGroupIndicator(null);
}
}
//FAQApdater1.java
package com.fys.abgsearchview;
import android.content.Context; import android.graphics.Typeface; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.TextView;
import java.util.HashMap; import java.util.List;
public class FAQAdapter1 extends BaseExpandableListAdapter { private Context ctx; private HashMap> FAQ_Category; private List FAQ_List; private ExpandableListView Exp_list; private int len; private int groupPosition; int lastExpandedGroupPosition;
public FAQAdapter1(Context ctx, HashMap<String, List<String>> FAQ_Category, List<String> FAQ_List) {
this.ctx = ctx;
this.FAQ_Category = FAQ_Category;
this.FAQ_List = FAQ_List;
}
@Override
public Object getChild(int parent, int child) {
return FAQ_Category.get(FAQ_List.get(parent)).get(child);
}
@Override
public long getChildId(int parent, int child) {
// TODO Auto-generated method stub
return child;
}
@Override
public View getChildView(int parent, int child, boolean lastChild,
View convertview, ViewGroup parentview) {
String child_title = (String) getChild(parent, child);
if (convertview == null) {
LayoutInflater inflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertview = inflator.inflate(R.layout.child_layout1, parentview, false);
}
TextView child_textview = (TextView) convertview.findViewById(R.id.child_txt);
child_textview.setText(child_title);
return convertview;
}
@Override
public int getChildrenCount(int parent) {
return FAQ_Category.get(FAQ_List.get(parent)).size();
}
@Override
public Object getGroup(int arg0) {
// TODO Auto-generated method stub
return FAQ_List.get(arg0);
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return FAQ_List.size();
}
@Override
public long getGroupId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getGroupView(int parent, boolean isExpanded, View convertview, ViewGroup parentview) {
// TODO Auto-generated method stub
String group_title = (String) getGroup(parent);
if (convertview == null) {
LayoutInflater inflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertview = inflator.inflate(R.layout.parent_layout1, parentview, false);
}
TextView parent_textview = (TextView) convertview.findViewById(R.id.parent_txt);
parent_textview.setTypeface(null, Typeface.BOLD);
parent_textview.setText(group_title);
return convertview;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int parent, int child) {
// TODO Auto-generated method stub
return false;
}
}
Also, do I need to do any changes in the Manifest file and, if so, what changes do I need?
Aucun commentaire:
Enregistrer un commentaire