我创建了一个网格视图应用程序,现在工作正常,显示网格视图中的所有图像。现在我想在全屏显示所选图像,但我收到错误。我的网格视图图像是在url链接下载的。我的url链接存储在数组列表中。如何解决这个错误? 错误类名称为FullImageActivity.class
错误:imageAdapter1.GridViewConfig cannot be resolved or is not a field
错误行:
imageView.setImageResource(imageAdapter1.GridViewConfig.getResim_list().get(position));
这是我的编码:
public class FullImageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter1 = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter1.GridViewConfig.getResim_list().get(position));
}
}
ImageAdapter.class
public class ImageAdapter extends BaseAdapter implements ListAdapter {
private Context context;
public ImageAdapter(Context context) {
super();
this.context = context;
//Listeye image url si ekliyor
GridViewConfig.addImageUrls();
}
@Override
public int getCount() {
return GridViewConfig.getResim_list().size();
}
@Override
public Object getItem(int position) {
return GridViewConfig.getResim_list().get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if(convertView==null)
{
imageView=new ImageView(context.getApplicationContext());
//imageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+ id));
imageView.setLayoutParams(new GridView.LayoutParams(100,100));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(5,5,5,5);
}else{
imageView=(ImageView)convertView;
}
imageView.setImageDrawable(LoadImageFromURL(GridViewConfig.getResim_list().get(position)));
return imageView;
}
//Internetten imageleri stream olarak cekip drawable olsurturuyor.
private Drawable LoadImageFromURL(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src");
return d;
}catch (Exception e) {
System.out.println(e);
return null;
}
}
}
GridViewconfig.class
public class GridViewConfig {
private static ArrayList<String> resim_list=new ArrayList<String>();
public static int[] getResim_list;
public static ArrayList<String> getResim_list() {
return resim_list;
}
public static void setResim_list(ArrayList<String> resim_list) {
GridViewConfig.resim_list = resim_list;
}
public static void addImageUrls(){
resim_list.add("http://igen.com/Images/Home/Client-Logo.png");
}
}
MyGridView.class
public class MyGridView extends Activity {
private GridView girGridView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
girGridView=(GridView) findViewById(R.id.gridView1_bir);
//ListView gibi buna da adapter set ediliyor.
girGridView.setAdapter(new ImageAdapter(getApplicationContext()));
girGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,long arg3) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
}
}
我发布了完整的源代码.....
答案 0 :(得分:0)
首先:GridViewConfig确实不是ImageAdapter的一个字段。
第二:
imageView.setImageResource(imageAdapter1.GridViewConfig.getResim_list().get(position));
它不起作用:getResim_list()返回ArrayList,它包含String值NOT int
您可以尝试更改:
public class FullImageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
GridViewConfig.addImageUrls();
imageView.setImageDravable(LoadImageFromURL(GridViewConfig.getResim_list().get(position)));
}
private Drawable LoadImageFromURL(String url) {
....
}
}
但在我看来,你应该重写所有代码。主要问题:图纸必须装在一个单独的线程中。