Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.example.rama.hello.Bean.RowItem;
- import com.example.rama.hello.R;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by RAMA on 10/25/2016.
- */
- public class CustomAdapter extends ArrayAdapter<RowItem> {
- Context mcontext;
- ArrayList<RowItem> rowItem = new ArrayList<RowItem>();
- private RowItem row;
- RowItem data;
- public CustomAdapter(Context context, int resourceId,
- ArrayList<RowItem> items) {
- super(context, resourceId, items);
- this.mcontext = context;
- }
- @Override
- public int getCount()
- {
- return rowItem.size();
- }
- @Override
- public long getItemId(int position) {
- return rowItem.indexOf(getItem(position));
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent)
- {
- if (convertView == null)
- {
- LayoutInflater mInflater = (LayoutInflater) mcontext
- .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
- convertView = mInflater.inflate(R.layout.list_item,parent,false);
- }
- ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
- TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
- TextView txtSubTitle = (TextView) convertView.findViewById(R.id.sub_title);
- TextView txtRightTitle = (TextView) convertView.findViewById(R.id.right_title);
- RowItem row_pos = getItem(position);
- // setting the image resource and title,subtitle,Righttitle
- File imgFile = new File(row_pos.getIcon());
- if(imgFile.exists()){
- Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
- imgIcon.setImageBitmap(myBitmap);
- }
- if(row_pos.getTitle() == " ")
- txtTitle.setText(row_pos.getPhone_number());
- else
- txtTitle.setText(row_pos.getTitle());
- txtSubTitle.setText(row_pos.getSub_title());
- txtRightTitle.setText(row_pos.getRight_title());
- return convertView;
- }
- }
- public CustomAdapter(Context context, int resourceId,
- ArrayList<RowItem> items) {
- super(context, resourceId, items);
- rowItem =items; // add this line
- this.mcontext = context;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement