Gooday
Below is my static code in java(android studio) and i have a listview linked to a layout and a class which must dynamically populate recent posts in a forum app i am designing. each listitem has drawable image of user who posted and information about the question posted on the same list item. i want the list to be created dynamically lets say a user posts "need help with etc " and the string[] userpost updates. Profile image is also loaded on the list item dynamically on the app. in other words i want to replace the static string "need help with etc " with string from runtime. The profile image as well with a image link at runtime.
********************************small sample code from
activity_main class
**************************
String [] web= { "need help with etc "};
Integer[] imageId = {
R.drawable.profile_image,
}
********************************
code for the custom list array
**********************************************************
code for the custom list array
package com.example.vtutor;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomList extends ArrayAdapter<String> {
public static int managani;
private final Activity context;
private final String[] web;
private final Integer[] imageId;
public CustomList(Activity context,
String[] web, Integer[] imageId) {
super(context, R.layout.list_single, web);
this.context = context;
this.web = web;
this.imageId = imageId;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
TextView zuva = (TextView) rowView.findViewById(R.id.tipedate);
txtTitle.setText(web[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
***********************************************************************************
code from the activity_main class
What I have tried:
String [] userpost = { "need help with etc "};
Integer[] imageId = {
R.drawable.profile_image,
}