Class Issue (The type XXX is already defined )
Posted
by
Android Stack
on Stack Overflow
See other posts from Stack Overflow
or by Android Stack
Published on 2012-04-14T23:16:21Z
Indexed on
2012/04/14
23:30 UTC
Read the original article
Hit count: 997
I have listview app exploring cities each row point to diffrent city , in each city activity include button when clicked open new activity which is infinite gallery contains pics of that city , i add infinite gallery to first city and work fine , when i want to add it to the second city , it gave me red mark error in the class as follow :
1- The type InfiniteGalleryAdapter is already defined.
2-The type InfiniteGallery is already defined.
i tried to change class name with the same result ,i delete R.jave and eclipse rebuild it with same result also i uncheck the java builder from project properties ,get same red mark error.
please any help and advice will be appreciated
thanks
My Code :
public class SecondCity extends Activity {
/** Called when the activity is first created. */
@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");
}
InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne);
galleryOne.setAdapter(new InfiniteGalleryAdapter(this));
}
}
class InfiniteGalleryAdapter extends BaseAdapter {
**//red mark here (InfiniteGalleryAdapter)**
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); }
public class ViewHolder{
public TextView text;
public ImageView image; }
private int[] images = { R.drawable.pic_1, R.drawable.pic_2,
R.drawable.pic_3, R.drawable.pic_4,
R.drawable.pic_5 };
private String[] name = { "This is first picture (1) " ,
"This is second picture (2)",
"This is third picture (3)",
"This is fourth picture (4)",
" This is fifth picture (5)", };
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);
return i; }
}
class InfiniteGallery extends Gallery {
**//red mark here (InfiniteGallery)**
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(){
// These are just to make it look pretty
setSpacing(25);
setHorizontalFadingEdgeEnabled(false);
}
public void setResourceImages(int[] name){
setAdapter(new InfiniteGalleryAdapter(getContext(), name));
setSelection((getCount() / 2));
}
}
© Stack Overflow or respective owner