Skip to content

Instantly share code, notes, and snippets.

@jamesgathu
Last active April 3, 2020 08:25
Show Gist options
  • Save jamesgathu/17acf4908c78775c717afd0f2665e064 to your computer and use it in GitHub Desktop.
Save jamesgathu/17acf4908c78775c717afd0f2665e064 to your computer and use it in GitHub Desktop.
ArrayAdapter with custom view using anonymous class
periodsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{"loading..."}) {
View render(View convertView, int position) {
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.single_month, null);
}
// TODO set some data to views
return convertView;
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return render(convertView, position);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return render(convertView, position);
}
@Nullable
@Override
public String getItem(int position) {
return dataSource.get(position);
}
};
@jamesgathu
Copy link
Author

Assuming that the data is being loaded from as server.

All you need here is to override getDropDownView and getView.

you can even got as far as showing different views

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment