Widget - Spinner Custome

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

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key