String[] countryNames={"India","China","Australia"};
int flags[] = {R.drawable.icon1, R.drawable.icon2, R.drawable.icon3};
CustomAdapter customAdapter=new CustomAdapter(getApplicationContext(),flags,countryNames);
spinner1.setAdapter(customAdapter);
}
public class CustomAdapter extends BaseAdapter {
Context context;
int flags[];
String[] countryNames;
LayoutInflater inflter;
public CustomAdapter(Context applicationContext, int[] flags, String[] countryNames) {
this.context = applicationContext;
this.flags = flags;
this.countryNames = countryNames;
inflter = (LayoutInflater.from(applicationContext));
}
@Override
public int getCount() {
return flags.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.custom, null);
ImageView icon = (ImageView) view.findViewById(R.id.imageview1);
TextView names = (TextView) view.findViewById(R.id.textview1);
icon.setImageResource(flags[i]);
names.setText(countryNames[i]);
return view;
}
//Create Custom with custom.xml name
//add imageview1 and textview1
Komentar