ListView is getting populated with same values - java

What happens is that I have a ArrayList<Pair<String, String>> and when I loop through that list in order to add the pair to a listview with two separate columns using a list adapter, I try to add the pair's first string to a certain textview and then the second string to certain textview, then it loops through the whole list and then adds in identical values to all lines.
Code for list adapter:
package com.example.test2;
import android.content.Context;
import android.util.Log;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
public class ThreeColumn_ListAdapter extends ArrayAdapter<Pair<String, String>> {
private LayoutInflater mInflater;
private ArrayList<Pair<String, String>> news;
private int mViewResourceId;
public ThreeColumn_ListAdapter(Context context, int textViewResourceId, ArrayList<Pair<String, String>> news) {
super(context, textViewResourceId, news);
this.news = news;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mViewResourceId = textViewResourceId;
}
public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(mViewResourceId, null);
TextView firstName = convertView.findViewById(R.id.textFirstName);
TextView lastName = convertView.findViewById(R.id.textLastName);
//TextView favFood = convertView.findViewById(R.id.textFavFood);
Log.i("n2",news.toString());
for(int j=0;j<news.size();j++){
firstName.setText(news.get(j).first);
lastName.setText(news.get(j).second);
}
return convertView;
}
}
What is stored in ArrayList<Pair<String, String>> news:
[Pair{usd -0.8068}, Pair{eur 0.5327}, Pair{gbp 1.2172}, Pair{nzd -2.7538}, Pair{cad 0.7586}, Pair{aud -1.7719}, Pair{chf 0.9591}, Pair{jpy 1.8649}]
Output viewed in listview layout:
Pair{jpy 1.8649} with pair's first value in textview firstName iterated 8 times and the pair's second value in textview lastName iterated 8 times and the 8 being the length of the ArrayList<Pair<String, String>> news

Figured it out, all I had to do was remove the for loop and do just news.get(position).first instead of doing a loop for news, since listview does a loop naturally.
So previously:
public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(mViewResourceId, null);
TextView firstName = convertView.findViewById(R.id.textFirstName);
TextView lastName = convertView.findViewById(R.id.textLastName);
//TextView favFood = convertView.findViewById(R.id.textFavFood);
Log.i("n2",news.toString());
for(int j=0;j<news.size();j++){
firstName.setText(news.get(j).first);
lastName.setText(news.get(j).second);
}
return convertView;
}
Correct Way:
public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(mViewResourceId, null);
TextView firstName = convertView.findViewById(R.id.textFirstName);
TextView lastName = convertView.findViewById(R.id.textLastName);
//TextView favFood = convertView.findViewById(R.id.textFavFood);
firstName.setText(news.get(position).first);
lastName.setText(news.get(position).second);
return convertView;
}

Related

Listview custom adapter - row loses content after new item is added

I am using a custom listview adapter to capture multiple objects of the same domain class Food. This class is:
public class Food {
public String Item;
public String Description;
public int count;
}
My custom Adapter is:
public class FoodAdapter extends ArrayAdapter<Food> {
private final Context context;
private final ArrayList<Food> itemsArrayList;
EditText item
EditText desc
EditText count;
public ArrayList<Food> getItemsArrayList() {
return itemsArrayList;
}
public FoodAdapter(Context context, ArrayList<Food> itemsArrayList) {
super(context, R.layout.fr_row, itemsArrayList);
//super(context, itemsArrayList);
this.context = context;
this.itemsArrayList = itemsArrayList;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// 1. Create inflater
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// 2. Get rowView from inflater
View rowView = inflater.inflate(R.layout.fr_row, parent, false);
// 3. Get the two text view from the rowView
item= (EditText) rowView.findViewById(R.id.f_item);
desc= (EditText) rowView.findViewById(R.id.f_desc);
count = (EditText) rowView.findViewById(R.id.f_count);
return rowView;
}
}
And my ActivityThat coordinates this listview is:
package com.example.foodie;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.ListView;
public class FoodActivity extends AppCompatActivity {
ListView lv;
FoodAdapter adapter;
ArrayList<Food> fList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frmorning);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setContentView(R.layout.activity_frmorning);
lv = (ListView) findViewById(R.id.list);
fList = new ArrayList<Food>();
adapter =new FoodAdapter(this, fList);
lv.setAdapter(adapter);
}
public void addItems(View v) {
fList.add(new Food());
adapter.notifyDataSetChanged();
}
}
This addItems is a button on the layout (in FoodActivity). When I tap on the add, I get the new row. But, the rows lose all content after the new row is added. They all are blank. What is causing this behaviour and how to solve? Also, how can I bind the EditText fields to the data in the ArrayList, so that when I call getItemsArrayList() I get the correct ArrayList that corresponds to the screen display?
When you are not using Holder so getView() method will call findViewById() as many times as you row(s) will be out of View. So if you have 1000 rows in List and 990 rows will be out of View then 990 times will be called findViewById() again.
Holder design pattern is used for View caching - Holder (arbitrary) object holds child widgets of each row and when row is out of View then findViewById() won't be called but View will be recycled and widgets will be obtained from Holder.
public class FoodAdapter extends ArrayAdapter<Food>
{
private final Context context;
private final ArrayList<Food> itemsArrayList;
public FoodAdapter(Context context, ArrayList<Food> itemsArrayList) {
{
super(context, itemsArrayList);
this.context = context;
this.itemsArrayList = itemsArrayList;
}
#Override
public int getCount()
{
return itemsArrayList.size();
}
#Override
public Object getItem(int position)
{
return itemsArrayList.get(position);
}
#Override
public long getItemId(int position)
{
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null)
{
holder = new ViewHolder();
LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fr_row, parent, false);
holder.text = (EditText ) convertView.findViewById(R.id.edittext);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(itemsArrayList.get(position));
return convertView;
}
class ViewHolder
{
EditText item
EditText desc
EditText count;
}
}`enter code here`

i"m using custom list have two buttons, one for and second one for whatsaap

i"m using custom list have two buttons, one for and second one for whatsaap. my problem is when i"m click first button then make a phone call its not working for me... please help me
custom list :
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Movie> movieItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public CustomListAdapter(Activity activity, List<Movie> movieItems) {
this.activity = activity;
this.movieItems = movieItems;
}
#Override
public int getCount() {
return movieItems.size();
}
#Override
public Object getItem(int location) {
return movieItems.get(location);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.list_row, null);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
NetworkImageView thumbNail = (NetworkImageView) convertView
.findViewById(R.id.thumbnail);
TextView title = (TextView) convertView.findViewById(R.id.title);
TextView rating = (TextView) convertView.findViewById(R.id.rating);
TextView genre = (TextView) convertView.findViewById(R.id.genre);
Button year = (Button) convertView.findViewById(R.id.releaseYear);
year.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(activity, "ramu...", Toast.LENGTH_LONG).show();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
}
});
// getting movie data for the row
Movie m = movieItems.get(position);
// thumbnail image
thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);
System.out.println("thumbNail===============>"+thumbNail);
// title
title.setText(m.getTitle());
// rating
rating.setText("Rating: " + String.valueOf(m.getRating()));
// release year
year.setText(String.valueOf(m.getYear()));
return convertView;
}
private void startActivity(Intent callIntent) {
// TODO Auto-generated method stub
}
}
`
You are committing few mistakes which cannot be ignored.
Listview recycles views on scroll, so it is very important that you handle this check. Not doing so will cause views inflation at wrong positions. Use ViewHolder
Solution:
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
/* This is where you initialize new rows, by:
* - Inflating the layout,
* - Instantiating the ViewHolder,
* - And defining any characteristics that are consistent for every row */
} else {
/* Fetch data already in the row layout,
* primarily you only use this to get a copy of the ViewHolder */
}
/* Set the data that changes in each row, like `title` and `size`
* This is where you give rows there unique values. */
return convertView;
}
You need to implement OnClickListener outside of checks like:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_row, null);
NetworkImageView thumbNail = (NetworkImageView) convertView
.findViewById(R.id.thumbnail);
TextView title = (TextView) convertView.findViewById(R.id.title);
TextView rating = (TextView) convertView.findViewById(R.id.rating);
TextView genre = (TextView) convertView.findViewById(R.id.genre);
Button year = (Button) convertView.findViewById(R.id.releaseYear);
}else {
}
year.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(activity, "ramu...", Toast.LENGTH_LONG).show();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
}
});
// getting movie data for the row
Movie m = movieItems.get(position);
// thumbnail image
thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);
System.out.println("thumbNail===============>"+thumbNail);
// title
title.setText(m.getTitle());
// rating
rating.setText("Rating: " + String.valueOf(m.getRating()));
// release year
year.setText(String.valueOf(m.getYear()));
return convertView;
}
Initialize ImageLoader in adapter constructor:

Change the icon of one row of a ListView

I am displaying some rows in my ListView and want to change only one of the row, by seeing if any of the date in the list matches today's date.
My partial code is:
DateFormat df = new SimpleDateFormat("EEEEE, LLLL d", Locale.US);
String[] suspendedDates = {
"Tuesday, January 1",
"Wednesday, April 16",
"Monday, October 6",
"Wednesday, December 25"
};
lvDisplay = (ListView) findViewById(R.id.lvDisp);
for (int i = 0; i < suspendedDates.length; i ++) {
sDate = suspendedDates[i];
sReason = datesReason[i];
if (Arrays.asList(suspendedDates).contains(df.format(Calendar.getInstance(Locale.US).getTime()))) {
inIconShow = R.drawable.caliconpressed; //if today matches display a different drawable
contents.add(new SetRows(inIconShow, sDate, sReason));
}
if (!Arrays.asList(suspendedDates).contains(df.format(Calendar.getInstance(Locale.US).getTime()))) {
inIconShow = R.drawable.calicon; //if today doesn't match the array display the default drawable
contents.add(new SetRows(inIconShow, sDate, sReason));
}
}
// Now set your adapter.
adapter = new SetRowsCustomAdapter(MainActivity.this, R.layout.listdates, contents);
lvDisplay.setAdapter(adapter);
SetRowsCustomAdapter class:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
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 SetRowsCustomAdapter extends ArrayAdapter<SetRows> {
Context context;
int layoutResourceId;
ArrayList<SetRows> data=new ArrayList<SetRows>();
public SetRowsCustomAdapter(Context context, int layoutResourceId, ArrayList<SetRows> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ImageHolder();
holder.txtTitle = (TextView)row.findViewById(R.id.tvDateVal);
//holder.txtTitle.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/robm.ttf"));
holder.imgIcon = (ImageView)row.findViewById(R.id.ivIcon0);
holder.txtID = (TextView)row.findViewById(R.id.tvReasonVal);
//holder.txtID.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/robm.ttf"));
row.setTag(holder);
}
else
{
holder = (ImageHolder)row.getTag();
}
SetRows myImage = data.get(position);
holder.txtTitle.setText(myImage.name);
holder.txtID.setText(myImage.id);
int outImage=myImage.image;
holder.imgIcon.setImageResource(outImage);
return row;
}
static class ImageHolder
{
ImageView imgIcon;
TextView txtTitle;
TextView txtID;
}
}
So the 4th row should have a different icon and the other 3 should have default icon. What is happening is if the date matches, every row has the different icon, otherwise every row has the default icon.
How do I fix it?
if you want change the image you can do in getView method like bellow code:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ImageHolder();
holder.txtTitle = (TextView)row.findViewById(R.id.tvDateVal);
//holder.txtTitle.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/robm.ttf"));
holder.imgIcon = (ImageView)row.findViewById(R.id.ivIcon0);
holder.txtID = (TextView)row.findViewById(R.id.tvReasonVal);
//holder.txtID.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/robm.ttf"));
row.setTag(holder);
}
else
{
holder = (ImageHolder)row.getTag();
}
SetRows myImage = data.get(position);
holder.txtTitle.setText(myImage.name);
holder.txtID.setText(myImage.id);
int outImage=myImage.image;
if (data.getValue)
holder.imgIcon.setImageResource(deferentIcon);
else
holder.imgIcon.setImageResource(defaultIcon);
return row;
}
and if you want change multi row icons you can send one list of your row and check in that, and for refresh you list use adapter.notifyDataSetChanged()
Edit
for your situation you can add on boolean value in your DS and if date equal set true otherwise set else that and in if statement check that
Use viewHolder in adapter then use notifyDataSetChanged() in adapter;
I already used and it will help.

Delete item from listview

I have listview which contains textview and buttons. When i delete listview item and i try to scroll down, i get exception on this:
BuildQueue eile = countryList.get(position);
Exception:
02-08 19:11:04.279: E/AndroidRuntime(10509): java.lang.IndexOutOfBoundsException: Invalid index 15, size is 15
Seems i do not updating something when i delete item from listview. I think i have problem with ViewHolder, but i do not know what kind of...
My ArrayAdapter code:
public class MyCustomAdapter extends ArrayAdapter<BuildQueue> {
private ArrayList<BuildQueue> countryList;
public MyCustomAdapter(Context context, int textViewResourceId,ArrayList<BuildQueue> countryList) {
super(context, textViewResourceId, countryList);
this.countryList = new ArrayList<BuildQueue>();
this.countryList.addAll(countryList);
}
private class ViewHolder {
TextView code;
TextView field;
Button del;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.queue_buildings, null);
holder = new ViewHolder();
holder.code = (TextView) convertView.findViewById(R.id.code);
holder.field = (TextView) convertView.findViewById(R.id.field_text);
holder.del = (Button) convertView.findViewById(R.id.del_button);
convertView.setTag(holder);
holder.del.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Button del_button = (Button) v;
BuildQueue building = (BuildQueue) del_button.getTag();
countryList.remove(building);
dataAdapter.notifyDataSetChanged();
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
BuildQueue eile = countryList.get(position);
holder.code.setText(" ( Level: " + eile.getOld_level() + " to "+eile.getNew_level()+")");
holder.field.setText(eile.getNameSort());
holder.field.setTag(eile);
holder.del.setText("Delete");
holder.del.setTag(eile);
return convertView;
}
}
You are using a two arrays in your Adapter, but only changing one of them.
Every Adapter uses getCount() to determine how many row should be drawn. ArrayAdapter's getCount() simply asks for the size of the array that you pass to the super constructor here: super(context, textViewResourceId, countryList);. But you are also using a second, local array and when you delete a value from this countryList getCount() has no idea this happened which results in getView() throwing an IndexOutOfBoundsException...
Either extend BaseAdapter, or use ArrrayAdapter's methods like getItem(), add(), and remove() and remove your local data set.

ArrayAdapter is not refreshing itself (only the last element is updated)

As my post states, I can't seem to get my ArrayAdapter to update the whole list despite the call "adapter.notifyDataSetChanged();" Only the last element in the list is updated.
Can someone maby see what I'm doing wrong below??
Here is my custom adapter
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class WeatherAdapter extends ArrayAdapter<Weather>{
Context context;
int layoutResourceId;
Weather data[] = null;
private WeatherHolder holder;
private Weather weather;
public WeatherAdapter(Context context, int layoutResourceId, Weather[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new WeatherHolder();
holder.imgIcon = (TextView)row.findViewById(R.id.imgen);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
row.setTag(holder);
}
else
{
holder = (WeatherHolder)row.getTag();
}
weather = data[position];
holder.txtTitle.setText(weather.getName());
//holder.imgIcon.setText(Double.toString(weather.getBuyingRate()));
return row;
}
public void update(String buttonPressed){
if(buttonPressed == "Köp Kurs"){
holder.imgIcon.setText(Double.toString(weather.getBuyingRate()));//This updates only the last element in list but I want to update every element in the list
}
else if(buttonPressed == "Antal"){ holder.imgIcon.setText(Double.toString(weather.getNrOfSharesInPortfolio()));//This updates only the last element in list but I want to update every element in the list
}
}
static class WeatherHolder
{
TextView imgIcon;
TextView txtTitle;
}
}
And here is my main class, when I call "Update()" method only the last element in the list is updated but not the others. How can I update the whole list instead of just the last element in the list?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends Activity {
private ListView listView1;
private Button goButton;
private String[] listheader = {"Köp Kurs","Antal"};
private WeatherAdapter adapter;
private int totalElemInlist = listheader.length;
private int currentelemInList=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Weather weather_data[] = new Weather[]
{
new Weather("ABB", 56.0, 300),
new Weather("Volvo", 89.0,500),
new Weather("Astra Zeneca", 98.55, 50)
};
adapter = new WeatherAdapter(this,
R.layout.listview_item_row, weather_data);
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
listView1.addHeaderView(header);
goButton = (Button) findViewById(R.id.testButton);
goButton.setText(listheader[currentelemInList]);
listView1.setAdapter(adapter);
goButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
String buttonPressed = (String) ((Button) view).getText();
goThroughList(buttonPressed);
System.out.println("Button Clicked" + buttonPressed);
}
});
}
private void goThroughList(String buttonPressed){
currentelemInList++;
if(currentelemInList>=totalElemInlist){
currentelemInList=0;
}
goButton.setText(listheader[currentelemInList]);
if(buttonPressed == "Köp Kurs"){
System.out.println("Köp kurs");
adapter.update(buttonPressed);
adapter.notifyDataSetChanged();//This only updates the last element in list
}
else if(buttonPressed == "Antal"){
System.out.println("Antal");
adapter.update(buttonPressed);
adapter.notifyDataSetChanged();//This only updates the last element in list
}
System.out.println(currentelemInList);
}
}
How can I update the whole list instead of just the last element in the list?
You must make your changes happen in getView(). getView() redraws every row as they appear whenever the user scrolls the ListView or notifyDataSetChanged() is called. So the changes must happen in there otherwise they will be erased.
First create a new field variable in your adapter:
private String currentImage;
Second change update() to control the contents on imgIcon:
public void update(String buttonPressed){
currentImage = buttonPressed;
notifyDataSetChanged();
}
Last change getView() to display the current images for each row:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
...
weather = data[position];
holder.txtTitle.setText(weather.getName());
if(currentImage.equals("Köp Kurs")){
holder.imgIcon.setText(Double.toString(weather.getBuyingRate()));
}
else if(currentImage.equals("Antal")){
holder.imgIcon.setText(Double.toString(weather.getNrOfSharesInPortfolio()));
}
return row;
}
(You can also simplify goThroughList(), since the if-else contains the exact same code.)
You should compare string like this.
buttonPressed.equals("Köp Kurs")
I might be wrong , but I think problem is because you are holding only last element in your holder. The member variable "holder" in adapter should be array or list, and you should hold all element, and in update method you should iterate through holder array and change the text
public void update(String buttonPressed){
for(int index =0 ; index < holder.size();index++){
if(buttonPressed == "Köp Kurs"){
holder[index].imgIcon.setText(Double.toString(weather.getBuyingRate()));//This updates only the last element in list but I want to update every element in the list
}
else if(buttonPressed == "Antal"){ holder[index].imgIcon.setText(Double.toString(weather.getNrOfSharesInPortfolio()));//This updates only the last element in list but I want to update every element in the list
}
This should solve your problem

Categories