Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomGrid extends BaseAdapter {
- private Context mContext;
- private final String[] web;
- private final int[] Imageid;
- public CustomGrid(Context c,String[] web,int[] Imageid ) {
- mContext = c;
- this.Imageid = Imageid;
- this.web = web;
- }
- @Override
- public int getCount() {
- // TODO Auto-generated method stub
- return web.length;
- }
- @Override
- public Object getItem(int position) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public long getItemId(int position) {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // TODO Auto-generated method stub
- View grid;
- LayoutInflater inflater = (LayoutInflater) mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- if (convertView == null) {
- grid = new View(mContext);
- grid = inflater.inflate(R.layout.grid_single, null);
- TextView textView = (TextView) grid.findViewById(R.id.grid_text);
- ImageView imageView = (ImageView)grid.findViewById(R.id.grid_image);
- textView.setText(web[position]);
- imageView.setImageResource(Imageid[position]);
- } else {
- grid = (View) convertView;
- }
- return grid;
- }
- }
- public class SectionListAdapter extends BaseExpandableListAdapter {
- private Context context;
- private LayoutInflater inflater;
- private List<Section> sections;
- String[] web = {
- "Language",
- "Add to Favorite",
- } ;
- int[] imageId = {
- R.drawable.language,
- R.drawable.ic_action_favorite,
- };
- public SectionListAdapter(Context context, List<Section> sections) {
- this.sections = sections;
- this.inflater = LayoutInflater.from(context);
- this.context = context;
- }
- @Override
- public Object getChild(int groupPosition, int childPosition) {
- return sections.get(groupPosition).getSectionItems().get(childPosition);
- }
- @Override
- public long getChildId(int groupPosition, int childPosition) {
- return sections.get(groupPosition).getSectionItems().get(childPosition).getId();
- }
- @Override
- public int getChildrenCount(int groupPosition) {
- return sections.get(groupPosition).getSectionItems().size();
- }
- @Override
- public Object getGroup(int groupPosition) {
- return this.sections.get(groupPosition);
- }
- @Override
- public int getGroupCount() {
- return this.sections.size();
- }
- @Override
- public long getGroupId(int groupPosition) {
- return groupPosition;
- }
- @Override
- public boolean hasStableIds() {
- return true;
- }
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- return true;
- }
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent) {
- if (convertView == null) {
- convertView = inflater.inflate(R.layout.menu_sectionview,
- parent, false);
- }
- TextView textView = (TextView) convertView
- .findViewById(R.id.slidingmenu_section_title);
- textView.setText(((Section) getGroup(groupPosition)).getTitle());
- return convertView;
- }
- @Override
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- ViewGroup item = getChildViewGroup(convertView, parent);
- GridView grid = (GridView) item.findViewById(R.id.grid);
- CustomGrid adapter = new CustomGrid(parent.getContext(), web, imageId);
- grid.setAdapter(adapter);
- grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- Toast.makeText(parent.getContext(), "You Clicked at " +web[+ position], Toast.LENGTH_SHORT).show();
- }
- });
- return item;
- }
- private ViewGroup getChildViewGroup(View convertView, ViewGroup parent) {
- if (convertView instanceof ViewGroup)
- {
- return (ViewGroup) convertView;
- }
- Context context = parent.getContext();
- LayoutInflater inflater = LayoutInflater.from(context);
- ViewGroup item = (ViewGroup) inflater.inflate(R.layout.menu_sectionitem, parent, false);;
- return item;
- }
- public static Drawable getDrawableByName( String name, Context context ) {
- int drawableResource = context.getResources().getIdentifier(
- name,
- "drawable",
- context.getPackageName());
- if ( drawableResource == 0 ) {
- throw new RuntimeException("Can't find drawable with name: " + name );
- }
- return context.getResources().getDrawable(drawableResource);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement