我正在尝试在我的应用程序中使用Picasso并运行下面的简单实验:
public class MainActivity extends Activity {
public static final String TAG = MainActivity.class.getSimpleName();//prints name of class without package name
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image1 = (ImageView) findViewById(R.id.imageView);
ImageView image2 = (ImageView) findViewById(R.id.imageView2);
ImageView image3 = (ImageView) findViewById(R.id.imageView3);
ImageView image4 = (ImageView) findViewById(R.id.imageView4);
ImageView image5 = (ImageView) findViewById(R.id.imageView5);
ImageView image6 = (ImageView) findViewById(R.id.imageView6);
ImageView image7 = (ImageView) findViewById(R.id.imageView7);
ImageView image8 = (ImageView) findViewById(R.id.imageView8);
ImageView image9 = (ImageView) findViewById(R.id.imageView9);
ImageView image10 = (ImageView) findViewById(R.id.imageView10);
swap(image1);
}
public void swap(ImageView image){
Picasso.with(MainActivity.this)
.load("") // IMAGE URL HERE
.skipMemoryCache()
.fit()
.into(image);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@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);
}
}
我的布局中有7个图像视图,我只是想看看我是否可以使用毕加索从7个不同的网址中填充所有7个图片。在上面的脚本中,我试图让毕加索替换其中一个图像视图,但它不会这样做。该应用程序显示7个初始图像视图,但不会将它们换成URL中的图像。令人惊讶的是,没有控制台消息。