Reputation: 23
this is my code
// 1st gridview
prepareList1();
mAdapter = new GridView_Adapter(this,listAccName, listAccIcon);
gridView1 = (GridView) findViewById(R.id.gridview1;
gridView1.setAdapter(mAdapter);
gridView1.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Toast.makeText(Main.this,"position = " + position + ":"+ mAdapter.getItem(position) , Toast.LENGTH_SHORT).show();
}
});
// 2nd gridview
prepareList2();
mAdapter = new GridView_Adapter(this,listCatName, listCatIcon);
gridView2 = (GridView) findViewById(R.id.gridview2);
gridView2.setAdapter(mAdapter);
gridView2.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Toast.makeText(Main.this,"position = " + position + ":"+ mAdapter.getItem(position) , Toast.LENGTH_SHORT).show();
}
});
but when I click on the first gridview item, it shows the second gridview variable on Toast. I try making difference variable name, but the result is the same.
Thank you
Upvotes: 0
Views: 68
Reputation: 6533
GridView_Adapter mAdapter1 = new GridView_Adapter(this,listCatName, listCatIcon);
gridView2 = (GridView) findViewById(R.id.gridview2);
gridView2.setAdapter(mAdapter1);
Just change this three lines
Upvotes: 2