Android, GridView 实现点击后 显示大图 ImageView 我这个点击后怎么没反应,代码如下
packagecom.example.demo_stone_album;importandroid.app.Activity;importandroid.graphics...
package com.example.demo_stone_album;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
public class GridActivity extends Activity {
GridView mGridView;
ImageView big_imageview;
private String TAG = "GridActivity";
// ImageView mBigImageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
Log.d(TAG, "stone one");
mGridView = (GridView)this.findViewById(R.id.gridview01);
big_imageview = (ImageView) findViewById(R.id.bigimageview);
mGridView.setBackgroundColor(Color.BLUE);
// mBigImageView = (ImageView) findViewById(R.id.bigimageview);
final Integer[] mId =
{
R.drawable.v1,
R.drawable.v2,
R.drawable.v3,
R.drawable.v4,
R.drawable.v5,
R.drawable.v6,
R.drawable.v7,
R.drawable.v8,
R.drawable.v9,
R.drawable.v10,
R.drawable.v11,
R.drawable.v12,
R.drawable.v13,
R.drawable.v14,
R.drawable.v15,
R.drawable.v16,
R.drawable.v17,
R.drawable.v18
};
mGridView.setAdapter(new BaseAdapter() {
// ImageView bigimageview = new ImageView(GridActivity.this);
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
ImageView imageview = new ImageView(GridActivity.this);
imageview.setLayoutParams(new GridView.LayoutParams(130, 130));
imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageview.setImageResource(mId[position]);
return imageview;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mId.length;
}
});
mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
big_imageview = new ImageView(GridActivity.this);
big_imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
big_imageview.setImageResource(mId[position]);
return;
}
});
Log.d(TAG , "stone");
}
} 展开
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
public class GridActivity extends Activity {
GridView mGridView;
ImageView big_imageview;
private String TAG = "GridActivity";
// ImageView mBigImageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
Log.d(TAG, "stone one");
mGridView = (GridView)this.findViewById(R.id.gridview01);
big_imageview = (ImageView) findViewById(R.id.bigimageview);
mGridView.setBackgroundColor(Color.BLUE);
// mBigImageView = (ImageView) findViewById(R.id.bigimageview);
final Integer[] mId =
{
R.drawable.v1,
R.drawable.v2,
R.drawable.v3,
R.drawable.v4,
R.drawable.v5,
R.drawable.v6,
R.drawable.v7,
R.drawable.v8,
R.drawable.v9,
R.drawable.v10,
R.drawable.v11,
R.drawable.v12,
R.drawable.v13,
R.drawable.v14,
R.drawable.v15,
R.drawable.v16,
R.drawable.v17,
R.drawable.v18
};
mGridView.setAdapter(new BaseAdapter() {
// ImageView bigimageview = new ImageView(GridActivity.this);
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
ImageView imageview = new ImageView(GridActivity.this);
imageview.setLayoutParams(new GridView.LayoutParams(130, 130));
imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageview.setImageResource(mId[position]);
return imageview;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mId.length;
}
});
mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
big_imageview = new ImageView(GridActivity.this);
big_imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
big_imageview.setImageResource(mId[position]);
return;
}
});
Log.d(TAG , "stone");
}
} 展开
2个回答
展开全部
没反映是因为 onclick的Imageview跟你现在main布局完全没关系! 你可以addview进来或者其他的,你在onclick里面写的代码是乱写的吧~
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-05-13
展开全部
点击时 创建一个自定义dialog 把图片的ID传给它用应显示就行了
看你的代码 big_imageview不是已经被 findviewbyid 了吗
下面又重新new了是吗?你这new以后去哪显示你没有指定吧?
看你的代码 big_imageview不是已经被 findviewbyid 了吗
下面又重新new了是吗?你这new以后去哪显示你没有指定吧?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询