D
D
Dmitry Richter2015-12-31 00:39:24
Android
Dmitry Richter, 2015-12-31 00:39:24

How to fix error with getView() method in android?

There is a listView and its "children" have a picture and an inscription, in general, earlier in the getView method when I set the picture in this way:

if (title.getText() == "Text #1") {
                //new ImgLoad().execute();
                Picasso.with(retval.getContext()).load("http://i.imgur.com/DvpvklR.png").into(image_list_icon);
 
            } else
            if (title.getText() == "Text #2"){
                Picasso.with(retval.getContext()).load("http://127.0.0.1:59777/smb/192.168.0.250/Files/1.jpg").into(image_list_icon);
            }else
            if (title.getText() == "Text #3"){
                Picasso.with(retval.getContext()).load("http://127.0.0.1:59777/smb/192.168.0.250/Files/2.jpg").into(image_list_icon);
            }else
            if (title.getText() == "Text #4"){
                Picasso.with(retval.getContext()).load("http://127.0.0.1:59777/smb/192.168.0.250/Files/3.jpg").into(image_list_icon);
            }

Now I don't have a fixed length, but it can be different, I'm now taking it from a file. The problem is that when the position is greater than the length of the strings in the array, the application closes, and I need to fix it somehow, any suggestions?
Here is the code I was trying to do:
if (title.getText() == lines_image.get(i)) {
                  Picasso.with(retval.getContext()).load(url_first + lines_image.get(i)).into(image_list_icon);
               }

Here is my old class and here is the new one .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
one pavel, 2015-12-31
@onepavel

So check that the position does not go beyond the array

O
Oleg Gamega, 2015-12-31
@gadfi

what are the suggestions?

No offense, but the first thought is to tear off my hands ... the second one too, thank Cthulhu that it’s not for me to work with this ... and now it’s constructive:
1. put the adapters in a separate class and in a separate file
2. describe the models
3. feed the collection of models to the adapter
4. implement the adapter completely (not all methods are implemented)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question