I just did a little test using most of your code. It works so I suspect the
from
and
to
values you are passing to the
SimpleAdapter
constructor do not match those in the
event_item_list.xml
file.
MainActivity.java:
public class MainActivity extends AppCompatActivity
{
ProgressDialog pDialog;
ArrayList<HashMap<String, String>> EventList;
ListView lv;
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EventList = new ArrayList<HashMap<String, String>>();
lv = (ListView) findViewById(android.R.id.list);
new GetEvents().execute();
}
private class GetEvents extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0)
{
try
{
HashMap<String, String> event = new HashMap<>();
event.put("EventId", "ID1");
event.put("EventName", "Name1");
event.put("Description", "Description1");
event.put("VenueName", "Venue1");
EventList.add(event);
event = new HashMap<>();
event.put("EventId", "ID2");
event.put("EventName", "Name2");
event.put("Description", "Description2");
event.put("VenueName", "Venue2");
EventList.add(event);
event = new HashMap<>();
event.put("EventId", "ID3");
event.put("EventName", "Name3");
event.put("Description", "Description3");
event.put("VenueName", "Venue3");
EventList.add(event);
}
catch(Exception e)
{
Log.d("Test2", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
if (pDialog != null)
pDialog.dismiss();
try
{
ListAdapter adapter = new SimpleAdapter(MainActivity.this,
EventList,
R.layout.event_row,
new String[]{"EventName", "Description", "VenueName"},
new int[]{R.id.Eventname, R.id.Eventdescription, R.id.Venue});
lv.setAdapter(adapter);
}
catch(Exception e)
{
Log.d("Test2", e.getMessage());
}
}
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.MainActivity">
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
event_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/Eventname"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView android:id="@+id/Eventdescription"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView android:id="@+id/Venue"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>