用Picasso

时间:2016-04-14 13:51:09

标签: android arrays image picasso

我正在尝试用Picasso填充一系列ImageView。我从后端返回工作URL。但是,当我将URL应用于Picasso使用的url数组加载到ImageViews数组时,没有任何反应。

我找不到我可能出错的地方?

public class MemoriesActivity extends AppCompatActivity {
private ImageView image1,image2,image3,image4,image5,image6,image7,image8,image9,image10,image11,image12;

private String image1_url,image2_url,image3_url,image4_url,image5_url,image6_url,image7_url,image8_url,image9_url,
        image10_url,image11_url,image12_url;


private static final int SELECT_PICTURE = 1;

public ImageView[] images;


public String[] urlList = new String[12];
public static final String KEY_URL = "urls";

public boolean image1_exists,image2_exists,image3_exists,image4_exists,image5_exists,image6_exists,image7_exists,
        image8_exists,image9_exists,image10_exists,image11_exists,image12_exists;

public boolean[] existingArray = new boolean[]{image1_exists,image2_exists,image3_exists,image4_exists,image5_exists,
        image6_exists,image7_exists, image8_exists,image9_exists,image10_exists,image11_exists,image12_exists};

public UserFileMapping fileMapping;

public BackendlessUser user = Backendless.UserService.CurrentUser();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(savedInstanceState != null){
        urlList = savedInstanceState.getStringArray(KEY_URL);
    }
    setContentView(R.layout.activity_memories);

    image1 = (ImageView) findViewById(R.id.image1);
    image2 = (ImageView) findViewById(R.id.image2);
    image3 = (ImageView) findViewById(R.id.image3);
    image4 = (ImageView) findViewById(R.id.image4);
    image5 = (ImageView) findViewById(R.id.image5);
    image6 = (ImageView) findViewById(R.id.image6);
    image7 = (ImageView) findViewById(R.id.image7);
    image8 = (ImageView) findViewById(R.id.image8);
    image9 = (ImageView) findViewById(R.id.image9);
    image10 = (ImageView) findViewById(R.id.image10);
    image11 = (ImageView) findViewById(R.id.image11);
    image12 = (ImageView) findViewById(R.id.image12);

    images = new ImageView[] { image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, image11, image12 };





    downloadAndAttachImages();
}



@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putStringArray(KEY_URL,urlList);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.log_in_menu,menu);
    return true;
}

@Override
protected void attachBaseContext(Context newBase){
    super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public void downloadAndAttachImages(){

        Backendless.Data.of(UserFileMapping.class).find(new AsyncCallback<BackendlessCollection<UserFileMapping>>() {
            @Override
            public void handleResponse(BackendlessCollection<UserFileMapping> response) {
                Iterator<UserFileMapping> iterator = response.getCurrentPage().iterator();
                while(iterator.hasNext()){
                    UserFileMapping fileMapping = iterator.next();

                    if(LocalPreferences.isPreferences1(MemoriesActivity.this)){

                        urlList[0] = fileMapping.url_1;
                        urlList[1] = fileMapping.url_2;
                        urlList[2] = fileMapping.url_3;
                        urlList[3] = fileMapping.url_4;
                        urlList[4] = fileMapping.url_5;
                        urlList[5] = fileMapping.url_6;
                        urlList[6] = fileMapping.url_7;
                        urlList[7] = fileMapping.url_8;
                        urlList[8] = fileMapping.url_9;
                        urlList[9] = fileMapping.url_10;
                        urlList[10] = fileMapping.url_11;
                        urlList[11] = fileMapping.url_12;


                    }

                    int size = urlList.length;
                    for (int i=0; i<size; i++){
                        Picasso.with(MemoriesActivity.this).load(urlList[i])
                                .into(images[i]);
                    }


                }
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                System.out.println("FAULT:" + fault.getCode());
            }
        });

}

}

0 个答案:

没有答案