I am having a hard time populating my ListView with dynamic items from my ArrayList and displaying them on the screen.
I have 2 xml files:
This is the activity file I want to populate my ListView with.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/activity_local_reps"
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"
tools:context="airbornegamer.com.grgr4.ActivityLocalReps">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
And my xml file I want to use to add an image/text to the listview:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/unknown_representative" />
<TextView
android:id="@+id/Itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="5dp"/>
In my file ActivityLocalReps.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_local_reps);
//setting up data and populating repData.
DisplayData(repData);
}
public void DisplayData(LocalRepData repData){
allRepData = repData.queryAllNeededRepData();
adapter=new ArrayAdapter<String>(this, R.layout.mylist, R.id.Itemname, allRepData);
}
My allRepData has multiple elements in it, however the adapter does not seem to hook up the data to my listView. Any help would be great, thanks!
**Edit 1
public class LocalRepData {
Context mContext;
public LocalRepData(Context mContext) {
this.mContext = mContext;
}
//other methods and stuff........
}
I'm using this class mostly for data retrieval, so currently I'm not extending anything there.