请我正在为网址制作更改图片,我有一个问题.....图像显示我想要的不是图片应该改变,取决于列表项目我点击.....它的工作当我使用r.drawable.image .......但是当我尝试使用getimage url并且它无法工作时无法工作....我使用了universal-image-loader-1.6.2.jar并且它给了我错误......这是我的代码..........并且注意,artp是我在数据库中保存的图片的url,它来自anoder类。 ..
这是我的代码
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class Music extends Activity{
TextView name,song,album,about;
String nam,son,albu,abou;
ImageView picc;
Button listen, download;
public int newInt;
MainActivity maa = new MainActivity();
Bundle extras = getIntent().getExtras();
String artp = extras.getString("artp");
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stu
super.onCreate(savedInstanceState);
setContentView(R.layout.music);
name= (TextView) findViewById(R.id.name);
song= (TextView) findViewById(R.id.song);
album=(TextView) findViewById(R.id.album);
about=(TextView) findViewById(R.id.about);
picc=(ImageView) findViewById(R.id.picc);
listen=(Button) findViewById(R.id.listen);
download=(Button) findViewById(R.id.download);
settext();
}
private void settext() {
Bundle extras = getIntent().getExtras();
newInt= extras.getInt("man");
String abt = extras.getString("abt");
String son = extras.getString("son");
String alb = extras.getString("alb");
String art = extras.getString("art");
String abt2 = extras.getString("abt2");
String son2 = extras.getString("son2");
String alb2 = extras.getString("alb2");
String art2 = extras.getString("art2");
if(newInt==0){
name.setText(art);
song.setText(son);
album.setText(alb);
about.setText(abt);
listen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent ner = new Intent(Intent.ACTION_VIEW, Uri.parse("http://media.takserver.in/Hamid/Music/1391/11/25/Imagine%20Dragons%20-%20Night%20Visions/Imagine%20Dragons%20-%20Night%20Visions/004-imagine_dragons-demons.mp3"));
startActivity(ner);
}
});
download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent ner = new Intent(Intent.ACTION_VIEW, Uri.parse("http://media.takserver.in/Hamid/Music/1391/11/25/Imagine%20Dragons%20-%20Night%20Visions/Imagine%20Dragons%20-%20Night%20Visions/004-imagine_dragons-demons.mp3"));
startActivity(ner);
}
});
// Get singletone instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
// Initialize ImageLoader with configuration. Do it once.
imageLoader.init(ImageLoaderConfiguration.createDefault(this));
// Load and display image asynchronously
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_launcher) //this is the image that will be displayed if download fails
.cacheInMemory()
.cacheOnDisc()
.build();
imageLoader.displayImage(artp, picc, options);
}
}
}
答案 0 :(得分:1)
Picasso允许在您的应用程序中轻松加载图像 - 通常只需一行代码!
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Android上图像加载的许多常见缺陷由Picasso
自动处理
答案 1 :(得分:1)
首先,您无法在onCreate()
方法之前执行此操作。
MainActivity maa = new MainActivity();
Bundle extras = getIntent().getExtras();
String artp = extras.getString("artp");
此外,您无法实例化您的活动。所以只需在onCreate()
方法中移动这些行。
Bundle extras = getIntent().getExtras();
String artp = extras.getString("artp");
同时制作String artp
全局变量,之后onCreate()
检索为
Bundle extras = getIntent().getExtras();
artp = extras.getString("artp");