Last active
April 3, 2020 08:25
-
-
Save jamesgathu/17acf4908c78775c717afd0f2665e064 to your computer and use it in GitHub Desktop.
ArrayAdapter with custom view using anonymous class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming that the data is being loaded from as server.
All you need here is to override
getDropDownView
andgetView
.you can even got as far as showing different views