I am new to Java programming / Android development – but I have been working through a few examples and have been trying to build a “mix-and-match” app with 3 scrolling galley views.
I have created the relative layout with 3 gallery views, and have defined 3 arrays to contain a list of images.
My problem is that I can’t seem to get the ImageAdapter to set the correct image resource for each gallery view (it duplicates the same images across all 3 galleries).
If I can just post the relevant sections of code:
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.main);
Gallery gTop = (Gallery) findViewById(R.id.gallery_top);
Gallery gMid = (Gallery) findViewById(R.id.gallery_mid);
Gallery gEnd = (Gallery) findViewById(R.id.gallery_end);
gTop.setAdapter(new ImageAdapter(this));
gMid.setAdapter(new ImageAdapter(this));
gEnd.setAdapter(new ImageAdapter(this));
}
Then another class sets the resources (hardcoded):
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mEndThumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
);
return i;
}
How can I remove this hardcoded link and check to see what object is calling getView and set the image resources accordingly?
Thanks, Alex
How about you add a new constructor to your adapter so that it reads
new ImageAdapter(this, Type.END)ornew ImageAdapter(this, Type.BEGIN)?Of course you would define a
enumto make the switch.Then, in the constructor simply check which one is requested and set the list.