0

I am trying to make a app with tabs showing listactivity and on the second tab a gallery. the first one seems working but how can i make the second one?I have used tutorials from android but those are not working.Someone help?

This for tab:

    host.addTab(host.newTabSpec("tab4")
            .setIndicator("Images")
            .setContent(new Intent(this,Images.class)));

the activity:

    public class Images extends Activity
{  @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
 }

 public class ImageAdapter extends BaseAdapter {
  int mGalleryItemBackground;
 private Context mContext;

 private Integer[] mImageIds = {
    R.drawable.icon,
    R.drawable.icon,
    R.drawable.icon
  };

 public ImageAdapter(Context c) {
 mContext = c;
 TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
 mGalleryItemBackground = a.getResourceId(
        R.styleable.HelloGallery_android_galleryItemBackground, 0);
 a.recycle();
   }

  public int getCount() {
  return mImageIds.length;
   }

public Object getItem(int position) {
return position;
 }

public long getItemId(int position) {
return position;
 }

public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);

i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);

return i;
}
}
}

please help?

Navdroid
  • 1,541
  • 3
  • 25
  • 52
  • I can't see why a tabbed activity running a Gallery wouldn't work properly. It would be easier to help if you posted your code. – jcxavier Dec 22 '11 at 11:20
  • Apparently nothing is wrong with the code you posted, seems like you used the sample code from HelloGallery and you are creating your tab properly (assuming it has been initialized). Just noticed you're not using android.R.styleable; did you copy the components to your res/ folder? Also, it could be a problem with the XML. – jcxavier Dec 22 '11 at 11:56
  • yeah i got the problem!thanx for the help!I wasted a whole day on this! – Navdroid Dec 22 '11 at 13:44
  • Please check [this][1]. I think you want to add a gallery to second tab. [1]: http://stackoverflow.com/questions/10227115/how-to-add-programmatically-generated-gallery-to-tab-layout/10227643#10227643 – saji159 May 22 '12 at 09:37

1 Answers1

0

Check this. TabContentFactory can give you the solution.

Community
  • 1
  • 1
saji159
  • 328
  • 7
  • 14