public class ListViewAdapter extends BaseAdapter {
// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
HashMap<String, String> resultp = new HashMap<String, String>();
private int[] colors = new int[] { 0xAAff0000, 0xAAffffff };
public ListViewAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
imageLoader = new ImageLoader(context);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView brand,price;
ImageView logo;
Button btn;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.test, parent, false);
// Get the position
resultp = data.get(position);
// Locate the TextViews in listview_item.xml
brand = (TextView) itemView.findViewById(R.id.tv_brand1);
price = (TextView) itemView.findViewById(R.id.tv_price11);
logo = (ImageView) itemView.findViewById(R.id.iv_logo11);
btn = (Button) itemView.findViewById(R.id.btn_view);
// Capture position and set results to the TextViews
brand.setText(resultp.get(CountryFragment.Name));
price.setText(resultp.get(CountryFragment.Price));
imageLoader.DisplayImage("http://jbtechnology.in/Krishna_Mobile/Logo/"+resultp.get(CountryFragment.Logo), logo);
// Capture ListView item click
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Get the position
resultp = data.get(position);
Intent intent = new Intent(context, detail.class);
intent.putExtra("Name", resultp.get(CountryFragment.Name));
intent.putExtra("Price", resultp.get(CountryFragment.Price));
intent.putExtra("Logo", "http://jbtechnology.in/Krishna_Mobile/Logo/"+resultp.get(CountryFragment.Logo));
intent.putExtra("Desc", resultp.get(CountryFragment.Desc));
context.startActivity(intent);
}
});
/*int colorPos = position % colors.length;
itemView.setBackgroundColor(colors[colorPos]);*/
return itemView;
}
// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
HashMap<String, String> resultp = new HashMap<String, String>();
private int[] colors = new int[] { 0xAAff0000, 0xAAffffff };
public ListViewAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
imageLoader = new ImageLoader(context);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView brand,price;
ImageView logo;
Button btn;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.test, parent, false);
// Get the position
resultp = data.get(position);
// Locate the TextViews in listview_item.xml
brand = (TextView) itemView.findViewById(R.id.tv_brand1);
price = (TextView) itemView.findViewById(R.id.tv_price11);
logo = (ImageView) itemView.findViewById(R.id.iv_logo11);
btn = (Button) itemView.findViewById(R.id.btn_view);
// Capture position and set results to the TextViews
brand.setText(resultp.get(CountryFragment.Name));
price.setText(resultp.get(CountryFragment.Price));
imageLoader.DisplayImage("http://jbtechnology.in/Krishna_Mobile/Logo/"+resultp.get(CountryFragment.Logo), logo);
// Capture ListView item click
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Get the position
resultp = data.get(position);
Intent intent = new Intent(context, detail.class);
intent.putExtra("Name", resultp.get(CountryFragment.Name));
intent.putExtra("Price", resultp.get(CountryFragment.Price));
intent.putExtra("Logo", "http://jbtechnology.in/Krishna_Mobile/Logo/"+resultp.get(CountryFragment.Logo));
intent.putExtra("Desc", resultp.get(CountryFragment.Desc));
context.startActivity(intent);
}
});
/*int colorPos = position % colors.length;
itemView.setBackgroundColor(colors[colorPos]);*/
return itemView;
}