Android Open Source - android-shuite-smoking Image Button Adapter






From Project

Back to project page android-shuite-smoking.

License

The source code is released under:

GNU General Public License

If you think the Android project android-shuite-smoking listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package udl.eps.smokerscontrol;
/*  w  w w .  j  a  v  a 2s.  c  o m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class ImageButtonAdapter extends BaseAdapter{
    private Context context;
    private List<ImageButton> imageButtonList;

    public ImageButtonAdapter (Context context){
        this.context = context;
        this.imageButtonList = new ArrayList<>();
    }

    public ImageButtonAdapter (Context context, List<ImageButton> lst){
        this.context = context;
        this.imageButtonList = lst;
    }

    public void addImageButton (ImageButton img){
        this.imageButtonList.add(img);
        this.notifyDataSetChanged();
    }

    public List<ImageButton> getImageButtonList(){
        return imageButtonList;
    }
    @Override
    public int getCount() {
        return this.imageButtonList.size();
    }

    @Override
    public Object getItem(int position) {
        return this.imageButtonList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.image_button_layout, parent, false);
        }

        ImageView img = (ImageView) view.findViewById(R.id.grid_image);
        img.setImageResource(imageButtonList.get(position).getImage());

        TextView tv = (TextView) view.findViewById(R.id.grid_text);
        tv.setText(imageButtonList.get(position).getButtonName());

        return view;
    }
}




Java Source Code List

udl.eps.smokerscontrol.ApplicationTest.java
udl.eps.smokerscontrol.BaseActivity.java
udl.eps.smokerscontrol.CommunityFragment.java
udl.eps.smokerscontrol.ImageButtonAdapter.java
udl.eps.smokerscontrol.ImageButton.java
udl.eps.smokerscontrol.MainActivity.java
udl.eps.smokerscontrol.MenuFragment.java
udl.eps.smokerscontrol.StatsFragment.java