i have listactivity forming 5 rows each row when clicked open new activity ,
i set separate class for each one (to customize it ) so i have 5 class:as (FirstCity,SecondCity,and so on )
in each row class i have many views , one of them button when clicked open customized infinite gallery ,
i want to pass this infinite gallery to 5 row classes by use putextra intent
but its not show the images ( show GalleryCity screen with customized title only)
, i have little experiance in android development ,
would you please help me , any advice will be appreciated , thanks
my code : GalleryCity class
public class GalleryCity extends Activity {
/** Called when the activity is first created. */
static String city;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// Set the layout to use
setContentView(R.layout.main);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
TextView tv = (TextView) findViewById(R.id.tv);
Typeface face=Typeface.createFromAsset(getAssets(),"BFantezy.ttf");
tv.setTypeface(face);
tv.setText("MY PICTURES");
}
Intent intent = getIntent();
city = intent.getStringExtra("galleryimags");
InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne);
}
}
class InfiniteGalleryAdapter extends BaseAdapter {
private Context mContext;
public InfiniteGalleryAdapter(Context c, int[] imageIds) {
this.mContext = c;
}
public int getCount() {
return Integer.MAX_VALUE;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
private LayoutInflater inflater=null;
public InfiniteGalleryAdapter(Context a) {
this.mContext = a;
inflater = (LayoutInflater)mContext.getSystemService (
Context.LAYOUT_INFLATER_SERVICE);
getImagesforCity();
}
private int[] images;
private void getImagesforCity() {
if(GalleryCity.city.equalsIgnoreCase("FirstCity")){
int[] imagestemp = {
R.drawable.pic_1, R.drawable.pic_2,
R.drawable.pic_3, R.drawable.pic_4,
R.drawable.pic_5
};
images=imagestemp;
}
if(GalleryCity.city.equalsIgnoreCase("SecondCity")){
int[] imagestemp = {
R.drawable.pic_6, R.drawable.pic_7,
R.drawable.pic_8, R.drawable.pic_9,
R.drawable.pic_10 };
images=imagestemp;
}
}
public class ViewHolder{
public TextView text;
public ImageView image;
}
private String[] name = {
" my picture " ,
" garden ",
" lake ",
" home land ",
" my car "
};
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = getImageView();
int itemPos = (position % images.length);
try {
i.setImageResource(images[itemPos]); ((BitmapDrawable) i.getDrawable()).
setAntiAlias (true);
}
catch (OutOfMemoryError e) {
Log.e("InfiniteGalleryAdapter", "Out of memory creating imageview. Using empty
view.", e);
}
View vi=convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.gallery_items, null);
holder=new ViewHolder(); holder.text=(TextView)vi.findViewById
(R.id.textView1);
holder.image=(ImageView)vi.findViewById(R.id.image);
vi.setTag(holder);}
else {
holder=(ViewHolder)vi.getTag();
}
holder.text.setText(name[itemPos]);
final int stub_id=images[itemPos];
holder.image.setImageResource(stub_id);
return vi;
}
private ImageView getImageView() {
ImageView i = new ImageView(mContext);
i.setBackgroundResource(android.R.drawable.btn_default);
return i;
}
}
class InfiniteGallery extends Gallery {
public InfiniteGallery(Context context) {
super(context);
init();
}
public InfiniteGallery(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public InfiniteGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init(){
setSpacing(25);
setHorizontalFadingEdgeEnabled(false);
}
public void setResourceImages(int[] name){
setAdapter(new InfiniteGalleryAdapter(getContext(), name));
setSelection((getCount() / 2));
}
}
in each row class (FirstCity,SecondCity,and so on ):
i put this code :
public void handleClick(View v){
Intent intent = new Intent(this, GalleryCity.class);
intent.putExtra("galleryimags",city);
startActivity(intent);
}
}
also please advice me how to set different images String names for each row class :
private String[] name = {
" my picture " ,
" garden ",
" lake ",
" home land ",
" my car "
};
No comments:
Post a Comment