【问题标题】:How will I maximize the imageView once the image is clicked on the ListView?在 ListView 上单击图像后,如何最大化 imageView?
【发布时间】:2014-03-01 17:23:16
【问题描述】:

我有一个列表视图,如果在列表视图上单击图像,我希望它可以全屏显示

这是我的代码:即单击列表视图时

ImageList.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {

                String Userid = ((TextView) view.findViewById(R.id.user_id)).getText().toString();
                String ScrapBookId = ((TextView) view.findViewById(R.id.photo_id)).getText().toString();
                // ---Starting new intent
                Intent in = new Intent(getApplicationContext(),FullImageActivity.class);

                in.putExtra("userid", Userid);
                in.putExtra("IMAGE",ScrapBookId);

                // ---starting new activity and expecting some response back
                startActivityForResult(in, 100);
                //Toast.makeText(getApplicationContext(), eventId, Toast.LENGTH_SHORT).show();

            }
        });

然后它会变成FullImageActivity 这里是代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

        setContentView(R.layout.fullimage);
        int imgid = getIntent().getIntExtra("IMAGE", 0);
        ImageView img = (ImageView)findViewById(R.id.imageView1);
        TextView txt = (TextView)findViewById(R.id.photo_id);
        img.setImageResource(imgid);
        txt.setText(imgid);
 }
}

但我认为没有图像通过:(我该怎么做?请帮助我:(谢谢

【问题讨论】:

  • 你传递图像 id 但如果没有图像则传递 -1 并在此处检测并检查是否得到 -1 然后只显示默认图像。

标签: android image listview android-listview fullscreen


【解决方案1】:

您在第一个活动中添加了一个带有键 "IMAGE"String 额外内容。在第二个活动中,您尝试使用getIntExtra("IMAGE", 0) 获取它。此键没有额外的 int,因此此调用将返回零。

我不确定你到底想做什么,但无论如何你试图获得的额外类型应该与你添加到意图的类型相匹配。

【讨论】:

    【解决方案2】:

    没有图像传递给新的 Activity。您的图像标识符是一个字符串(“ScrapBookId”),但您将其视为 OnCreate 中的资源标识符(整数)。

    假设你的drawables是资源(它们看起来是),记录你为每个imageView设置的resourceId如下:

        iv.setTag(R.drawable.ponies);  
    

    然后在onItemClick中,查找resourceId:

        ImageView iv = ((ImageView) view.findViewById(R.id.imageview1));
        int resId = (Integer) iv.getTag();
    
        in = new Intent(...)
        in.putExtra("IMAGE", resId);
    

    然后在onCreate中:

        resId = getIntent().getIntExtra("IMAGE", 0);
        img.setImageResource(resId);
    

    【讨论】:

      猜你喜欢
      • 2012-09-30
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 2022-01-05
      • 2016-07-21
      相关资源
      最近更新 更多