gpt4 book ai didi

java - 显示单击的网格图像的全尺寸图像

转载 作者:行者123 更新时间:2023-11-29 05:22:27 25 4
gpt4 key购买 nike

主要 Activity .java

    public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_grid);

// populate data
products = new ArrayList();
products.add(new Product("http://image1.jpg"));
products.add(new Product("http://image2.jpg"));
products.add(new Product("http://image3"));
products.add(new Product("http://image4"));

//
gvProducts = (GridView) findViewById( R.id.grid_products);
adapterProducts = new ProductListAdapterWithCache(this, products);
gvProducts.setAdapter(adapterProducts);




gvProducts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {


String path = (MainActivity.this, position);

Intent intent = new Intent(MainActivity.this, FullImageActivity.class);
intent.putExtra("IMAGEPATH",path);
startActivity(intent);
}
});

}

我正在 android studio 中开发简单的图像处理应用程序。我正在从 url 下载图像以在上面的网格中显示。我想在单击网格时在页面中显示完整图像。试图通过 Intent 传递位置但它显示错误这条线..

String path = (MainActivity.this, position);

FullImageActivity.java

    public class FullImageActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);
setContentView(R.layout.layout_fullscreen_image);
// selected item
int imageInt = getIntent().getIntExtra("IMAGEPATH", R.drawable.spinner);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageResource(imageInt);

}
}

我是初学者,如果我在基础知识上做错了什么,请指导我。

谢谢,

最佳答案

试试下面的代码:

gvProducts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {


Intent intent = new Intent(MainActivity.this, FullImageActivity.class);
intent.putExtra("IMAGEPATH",products.get(position).imagePath);
startActivity(intent);
}
});

在 Activity 中:

String path = getIntent().getStringExtra("IMAGEPATH");

关于java - 显示单击的网格图像的全尺寸图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24136831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com