Populate ListView from List<Object> - java

Basically I have a list of objects of class Ingredient which looks like this:
class Ingredient {
public int id;
public String name;
public Ingredient(String name) {
this.name = name;
}
}
so each object from list have a name.
Now to use ArrayAdapter I need to have a List of strings filled with names.
Is there any way to use ArrayAdapter with my list of Ingredients?
This is how it looks right now
List<Ingredient> ingredientsList= new ArrayList<Ingredient>();
ingredientsList.add(new Ingredient("foo"));
ingredientsList.add(new Ingredient("bar"));

Use the below. You can use a for loop and populate your ingredientsList. The below is just a example
List<Ingredient> ingredientsList= new ArrayList<Ingredient>();
Ingredient i= new Ingredient("foo");
ingredientsList.add(i);
Ingredient i1= new Ingredient("bar");
ingredientsList.add(i1);
Then
ListView lv = (ListView) findViewById(R.id.listview);
// initialize listview
lv.setAdpater(new CustomAdapterArrayAdapter(ActivityName.this,ingredientsList));
// set the custom adapter to listview
You can use a CustomAdapterArrayAdapter inflate a custom layout
public class CustomAarrayAdapter extends ArrayAdapter
{
List<Ingredient> ingredientsList;
public CustomArrayAdapter(Context context, List<Ingredient> list)
{
super(context,0,list);
ingredientList = list;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row,parent,false);
// inflate custom layout called row
holder = new ViewHolder();
holder.tv =(TextView) convertView.findViewById(R.is.textView1);
// initialize textview
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
Ingredient in = (Ingredient)ingredientsList.get(position);
holder.tv.setText(in.name);
// set the name to the text;
return convertView;
}
static class ViewHolder
{
TextView tv;
}
}
http://developer.android.com/training/improving-layouts/smooth-scrolling.html
ViewHolder is for smooth scrolling and performance
row.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:text="TextView" />
</RelativeLayout>
Edit:
Without using custom adapter
class Ingredient {
public int id;
public String name;
public Ingredient(String name) {
this.name = name;
}
#Override
public String toString() {
// TODO Auto-generated method stub
return this.name.toString();
}
}
Then
public class MainActivity extends Activity {
List<Ingredient> ingredientsList= new ArrayList<Ingredient>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i<10;i++)
{
ingredientsList.add(new Ingredient("foo"+i));
}
ArrayAdapter<Ingredient> adapter = new ArrayAdapter<Ingredient>(this,android.R.layout.simple_list_item_1,ingredientsList);
ListView lv= (ListView) findViewById(R.id.listView1);
lv.setAdapter(adapter);
}
}
Then
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
Snap

Extend the array adapter class:
public class MyAdapter extends ArrayAdapter<Ingredient> {
Activity activity;
public MyAdapter(Activity context, int resource,
List<Ingredient> objects) {
super(context, resource, objects);
this.activity = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
Ingredient currentIngredient = getItem(position);
//Do Something
....
}

Related

ListView does not show Custom Array Adapter (Android Studio/Java)

I have the problem that a ListView does not show my custom Array Adapter.
I tested it with an standart ArrayAdapter, which worked. I also tested if the ArrayList with the data exists, which was also the case.
ATM i think it's the Adapter, but i can't find the problem.
Where the List should be shown
public class LiSpellFragment extends Fragment {
private ArrayList<Spell> list;
public ListView lv_spellList;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_li_spell, container, false);
isList();
TestAdapter al = new TestAdapter(getContext(),R.layout.row_test, list);
lv_spellList.setAdapter(al);
return root;
}
void isList(){
if(this.list == null){
ArrayList<Spell> spellArrayList = new ArrayList<>();
Spell spell;
spell = new Spell("Hamlet");
spellArrayList.add(spell);
spell = new Spell("Carl");
spellArrayList.add(spell);
spell = new Spell("Frank");
spellArrayList.add(spell);
}
this.list = spellArrayList;
}
}
}
Custom Adapter Code
public class TestAdapter extends ArrayAdapter<Spell> {
ArrayList<Spell>list = new ArrayList<>();
int resource;
Context context;
public TestAdapter(#NonNull Context context, int resource, ArrayList<Spell> list) {
super(context, resource);
this.list = list;
this.resource = resource;
this.context = context;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
TextView tv = (TextView) convertView.findViewById(R.id.textView2);
tv.setText(list.get(position).getName());
return convertView;
}
}
XML of the displayed row
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
class Spell
public class Spell {
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

SearchView show me wrong matches

I have a SearchView and a ListView. My goal here is when I search for (for example) Toyota, I got result in the ListView with Toyota, and than when I click on it, Toyota save to another list.
Everything is working well, except the ListView. When I search for something, I get different result. For example if I search for Toyota, I got BMW or Mazda etc. but not Toyota. BUT, if I click on this result Toyota will be saved and not BMW or Mazda despite I click on them.
I think something with the ListView is not good, because in the background evertyhing is working well, but it's shown otherwise.
Here is my xml file:
<SearchView
android:id="#+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false">
<requestFocus />
</SearchView>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
I am using a custom row in my ListView, I don't think its affect any harm, but now I am even questioning my own existence :D So here it is the list_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name"
android:layout_centerVertical="true"
android:layout_marginLeft="28sp"
android:textColor="#73c993"/>
</RelativeLayout>
And the ListViewAdapter.java:
public class ListViewAdapter extends ArrayAdapter<String> {
ArrayList<String> list;
Context context;
public ListViewAdapter(Context context, ArrayList<String> items) {
super(context, R.layout.list_row, items);
this.context = context;
list = items;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_row, null);
TextView name = convertView.findViewById(R.id.name);
name.setText(list.get(position));
}
return convertView;
}
}
Finally, my HomeFragment.java:
public class HomeFragment extends Fragment implements SearchView.OnQueryTextListener {
SearchView editsearch;
static ListView listView;
static ListViewAdapter adapter;
static ArrayList<String> cars, selectedCars;
static Context context;
private HomeViewModel homeViewModel;
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
return inflater.inflate(R.layout.fragment_home, container, false);
}
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
listView = (ListView) view.findViewById(R.id.list);
cars = new ArrayList<>(Arrays.asList("Toyota", "BMW", "Mazda"));
selectedCars= new ArrayList<>();
context = getContext();
adapter = new ListViewAdapter(context, cars);
listView.setAdapter(adapter);
editsearch = (SearchView) view.findViewById(R.id.search);
editsearch.setOnQueryTextListener(this);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = adapter.getItem(position);
if (!(selectedCars.contains(item))) {
addItem(item);
makeToast(item + " added.");
} else {
makeToast(item + " already added.");
}
}
});
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return false;
}

Change style of only one item spinner android

I defined a spinner like this, with its own adapter.
How can I change the style of only one item of the spinner?
In particular I would like to change the color of the last string inserted in the spinner.
Thanks
Spinner spinner = findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, "List<String>");
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
You can create custom adapter for spinner, in adapter inside getView add a condition when a position is the last one, change a view(TextView) background color.
UPDATE :
create customAdapter
public class CustomAdapter extends BaseAdapter {
private final Context context;
private final List<String> list;
public CustomAdapter(#NonNull Context context, #NonNull List<String> list) {
this.context = context;
this.list = list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
View view;
if (convertView == null) {
view = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
} else {
view = convertView;
}
TextView textView = view.findViewById(R.id.textView_name);
textView.setText(list.get(position));
if (position == list.size() - 1) {
textView.setBackgroundResource(android.R.color.holo_blue_light);
}
return view;
}
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="#+id/textView_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:gravity="center"
android:textStyle="bold"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
then set customAdpater to spinner
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> list = new ArrayList<String>();
list.add("first");
list.add("second");
list.add("third");
list.add("forth");
Spinner spinner = findViewById(R.id.spinner);
CustomAdapter adapter = new CustomAdapter(this, list);
spinner.setAdapter(adapter);
}
result will be as the photo

how to create custom adapter to use cardview for list view inside fragment

i want to use card view inside my list view which is inside a fragment to show 2 variable, i already can connect to database and show only one variable "nama_matkul" from json into my list view, but i need to show "nama_matkul" and "sks" so i am creating a cardview but i am confused to make costum adapter for it
this is my json response
{
"error": false,
"matkul_mhs": [{
"nama_matkul": "matkul_3",
"sks": 3
}]}
this is my method inside fragment to initialize list view
public void initListView1(){
Call<MatkulMhs> getMatkulMhs = mApiService.getMatkulMhs(
mPrefs.getUserID());
getMatkulMhs.enqueue(new Callback<MatkulMhs>() {
#Override
public void onResponse(Call<MatkulMhs> call, Response<MatkulMhs> response) {
boolean iserror_ = response.body().getError();
if (iserror_ == false) {
List<Matkul_Mhs> list = new ArrayList<>();
list = response.body().getMatkulMhs();
nama_matkul = new String[list.size()];
for (int i =0;i<list.size();i++) {
nama_matkul[i] = list.get(i).getNamaMatkul();
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, nama_matkul);
listview1.setAdapter(adapter);
}
}
this is my cardview (form_mhs_02_cardview.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/rounded_sqrwht"
android:padding="10dp"
>
<TextView
android:id="#+id/tv_matkul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mata Kuliah 1 "
android:textSize="25dp"
android:textColor="#color/colorPrimaryDark"
android:textStyle=""
android:singleLine="true"
/>
<TextView
android:id="#+id/tv_sks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3 sks"
android:textSize="20dp"
android:textColor="#color/black"
android:singleLine="true"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
i found this answer from another post but still confuse to change into my needs
,post can be found at custom adapter for listview in fragment Android
public class CustomAdapter extends ArrayAdapter<HashMap<String,String>>
{
private ArrayList<HashMap<String,String>> callLogData;
private Context context;
private int resource;
private View view;
private Holder holder;
private HashMap<String,String> hashMap;
public CustomAdapter(Context context, int resource,ArrayList<HashMap<String, String>> objects)
{
super(context, resource, objects);
this.context=context;
this.resource=resource;
this.callLogData=objects;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(resource, parent,false);
holder=new Holder();
holder.text_matkul=(TextView)view.findViewById(R.id.tv_matkul);
holder.text_sks=(TextView)view.findViewById(R.id.tv_sks);
hashMap=callLogData.get(position);
Date date=new Date(Long.parseLong(hashMap.get(CallLog.Calls.DATE)));
java.text.DateFormat dateFormat=DateFormat.getDateFormat(context);
java.text.DateFormat timeformat=DateFormat.getTimeFormat(context);
holder.text_matkul.setText(hashMap.get(CallLog.Calls.NUMBER));
holder.text_sks.setText(timeformat.format(date));
return view;
}
public class Holder
{
TextView text_matkul;
TextView text_sks;
}
}
#togan-j-r please have a look at this example on this link https://medium.com/#Pang_Yao/android-fragment-use-recyclerview-cardview-4bc10beac446 and try to implement as per the demo example.
Use your Custom Adapter Class File Before SetAdapter.
CustomAdapter adapter = new CustomAdapter(getActivity(), android.R.layout.simple_list_item_1, nama_matkul);
public void initListView1(){
Call<MatkulMhs> getMatkulMhs = mApiService.getMatkulMhs(
mPrefs.getUserID());
getMatkulMhs.enqueue(new Callback<MatkulMhs>() {
#Override
public void onResponse(Call<MatkulMhs> call, Response<MatkulMhs> response) {
boolean iserror_ = response.body().getError();
if (iserror_ == false) {
List<Matkul_Mhs> list = new ArrayList<>();
list = response.body().getMatkulMhs();
nama_matkul = new String[list.size()];
for (int i =0;i<list.size();i++) {
nama_matkul[i] = list.get(i).getNamaMatkul();
}
CustomAdapter <String> adapter = new CustomAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, nama_matkul);
listview1.setAdapter(adapter);
}
}
public class CustomAdapter extends ArrayAdapter<HashMap<String, String>> {
private final ArrayList<HashMap<String, String>> callLogData;
private final Context context;
private final int resource;
/*
This TODO code won't cause any issue even if not done.
*/
//TODO : Check below comment
private View view;
//TODO :: NEED TO REMOVE as adapter handle multiple items therefore no meaning in having single field of holder object
private Holder holder;
//TODO :: NEED TO REMOVE same as above. you should get item from based on position provided in getView method no need to keep reference to it
private HashMap<String, String> hashMap;
public CustomAdapter(Context context, int resource, ArrayList<HashMap<String, String>> objects) {
super(context, resource, objects);
this.context = context;
this.resource = resource;
callLogData = objects;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Added local instance of holder
View view = inflater.inflate(resource, parent, false);
//Added local instance of holder
Holder holder = new Holder();
holder.text_matkul = (TextView) view.findViewById(R.id.tv_matkul);
holder.text_sks = (TextView) view.findViewById(R.id.tv_sks);
//Added local instance of holder
HashMap<String, String> hashMap = callLogData.get(position);
//Commenting below code
/*
Date date=new Date(Long.parseLong(hashMap.get(CallLog.Calls.DATE)));
java.text.DateFormat dateFormat=DateFormat.getDateFormat(context);
java.text.DateFormat timeformat=DateFormat.getTimeFormat(context);
*/
holder.text_matkul.setText(hashMap.get("nama_matkul"));
holder.text_sks.setText("sks");
return view;
}
public class Holder {
TextView text_matkul;
TextView text_sks;
}
}
public void initListView1() {
Call<MatkulMhs> getMatkulMhs = mApiService.getMatkulMhs(
mPrefs.getUserID());
getMatkulMhs.enqueue(new Callback<MatkulMhs>() {
#Override
public void onResponse(Call<MatkulMhs> call, Response<MatkulMhs> response) {
boolean iserror_ = response.body().getError();
if (iserror_ == false) {
List<Matkul_Mhs> list = new ArrayList<>();
list = response.body().getMatkulMhs();
ArrayList<HashMap<String, String>> nama_matkul = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("nama_matkul", list.get(i).getNamaMatkul());
item.put("sks", list.get(i).getSKS());
nama_matkul.add(item);
}
//Note: layout resource changed to your card view and ArrayAdapter to CustomAdapter
CustomAdapter adapter = new CustomAdapter(getActivity(), R.layout.form_mhs_02_cardview, nama_matkul);
listview1.setAdapter(adapter);
}
}
}
}

Android - Custom adapter with imageview and textview not displaying listview

I am working on a college project to build an android based mobile learning app. I'm using Parse for backend services. There is a class, namely 'Course' which contains name of the courses to be offered along with an icon for each course. I have written code for custom adapter to display a list of all the courses with icons. The project is executing but the list is not appearing. I cannot figure out what is going wrong.
Here is my SelectCourse.java code
final List<Item> items=new ArrayList<Item>();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Course");
query.orderByAscending("name");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
if (list.size() > 0)
for (int i = 0; i < list.size(); i++) {
final String course = list.get(i).getString("name");
ParseFile image = list.get(i).getParseFile("image");
//adapter.add(course.getString("name"));
image.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap icon = BitmapFactory.decodeByteArray(
data, 0, data.length);
Item item = new Item(icon, course);
items.add(item);
} else {
Toast.makeText(getApplicationContext(),
e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
}
} else {
Toast.makeText(getApplicationContext(),
e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
CustomAdapter adapter=new CustomAdapter(this,items);
ListView listView = (ListView) findViewById(R.id.course_list);
listView.setAdapter(adapter);
This is my CustomAdapter.java code
public class CustomAdapter extends BaseAdapter {
private Context context;
private List<Item> list;
CustomAdapter(Context context, List<Item> list){
this.context = context;
this.list = list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView=convertView;
if(rowView==null) {
ViewHolder viewHolder = new ViewHolder();
LayoutInflater layoutInflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = layoutInflater.inflate(R.layout.list_select_course, parent, false);
viewHolder.icon = (ImageView) rowView.findViewById(R.id.rowImageView);
viewHolder.text = (TextView) rowView.findViewById(R.id.rowTextView);
rowView.setTag(viewHolder);
}
ViewHolder viewHolder = (ViewHolder) rowView.getTag();
viewHolder.icon.setImageBitmap(list.get(position).image);
viewHolder.text.setText(list.get(position).text);
return rowView;
}}
Here are ViewHolder and Item
public class ViewHolder {
ImageView icon;
TextView text;}
public class Item {
Bitmap image;
String text;
Item(Bitmap image, String text){
this.image=image;
this.text=text;
}}
This is content_select_course.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.rsa.minerva.SelectCourseActivity"
tools:showIn="#layout/app_bar_select_course">
<ListView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/course_list"
android:layout_weight="1" />
And finally list_select_course.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:id="#+id/rowImageView"
android:layout_width="48dp"
android:layout_height="48dp" />
<TextView
android:id="#+id/rowTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorButton"
android:text="Hello World"/>
This part of the code:
query.findInBackground(new FindCallback<ParseObject>()
Doesn't run synchronously, meaning that you are actually creating an adapter with no data:
Put this snippet before you call the query.findInBackground():
CustomAdapter adapter=new CustomAdapter(this,items);
ListView listView = (ListView) findViewById(R.id.course_list);
listView.setAdapter(adapter);
And then inside the public void done() callback, put:
adapter.notifyDataSetChanged();
After you add the items to the list with items.add(item).
That should do it.

Categories