是否可以显示空的网格视图(它不像填充的那样显示,而是像单个粗体条线一样显示)。
所以我尝试用黑色可绘制图像填充它,然后它就像一个填充的图像一样显示出来。
我的应用程序包含两个网格视图,一个带有图像,一个看起来像空的。
用户可以从网格视图 1 中选择图像并将其放置在网格视图 2 上,
现在我想获取放置在网格视图 2 中的图像的标签。但我得到 Null 我是对还是错,请回复
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
GridView g=(GridView) findViewById(R.id.gridView1);
g.setAdapter(new ImageAdapter(getApplicationContext()));
GridView g2=(GridView) findViewById(R.id.gridView2);
g2.setAdapter(new ImageAdapter2(getApplicationContext()));
g.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v,
int position, long id)
{
System.out.println("pressent G1 child Tag is,,,,"+(Integer)g.getChildAt(tt).getTag());
}
});
g2.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v,
int position, long id)
{ ImageAdapter ia=new ImageAdapter(getApplicationContext());
/* ImageView imv;
if(v!=null)
{
imv=(ImageView)v;
}
else
{
imv=new ImageView(getApplicationContext());
imv.setLayoutParams(new GridView.LayoutParams(40,40));
imv.setScaleType(ScaleType.CENTER_CROP);
imv.setPadding(0,0,0,0);
imv.setBackgroundColor(5555);
} */
imv.setImageResource(ia.imageid[tt]);
System.out.println("tag of placed image is"+(Integer)g2.getChildAt(position).getTag());
// IN THIS GRIDVIEW2 PLEASE HELP ME HOW I CAN GET THE PLACED IMAGE TAG(the images which are in gridview1 and image placed in gridview2 are same but iam not able to get the tag it return null)
}
}
});
ImageAdapter.java
if(arg1!=null)
{
imv=(ImageView)arg1;
}
else
{
imv=new ImageView(cont);
imv.setLayoutParams(new GridView.LayoutParams(40,40));
imv.setScaleType(ScaleType.CENTER_CROP);
imv.setPadding(0,0,0,0);
}
imv.setTag(arg0);
imv.setImageResource(imageid[arg0]);
return imv;
ImageAdapter2.java
if(arg1!=null)
{
imv=(ImageView)arg1;
}
else
{
imv=new ImageView(cont);
imv.setLayoutParams(new GridView.LayoutParams(40,40));
imv.setScaleType(ScaleType.CENTER_CROP);
imv.setPadding(0,0,0,0);
}
imv.setImageResource(imageid[0]); //---> this is to set Black images in gridview so that it will look like a box
return imv;