2011-12-22 11 views
0

私はlistactivityを示すタブと2番目のタブにギャラリーを作ろうとしています。 最初のものは動作しているようですが、どうすれば2番目のものを作ることができますか?アンドロイドからチュートリアルを使用しましたが、動作していません。タブのタブ付きの画面でギャラリーを表示するにはどうすればいいですか?

この:

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

アクティビティ:

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; 
} 
} 
} 

助けてください?

+0

ギャラリーを実行しているタブ付きアクティビティが正しく機能しない理由がわかりません。コードを投稿した方が助けが簡単です。 – jcxavier

+0

完了しました! – Navdroid

+0

あなたが投稿したコードに間違いはありませんが、HelloGalleryのサンプルコードを使用しているように見えます(タブが正しく初期化されていると仮定して)。ちょうどあなたがアンドロイドを使用していないことに気づいた。R.styleable; res/folderにコンポーネントをコピーしましたか?また、XMLの問題かもしれません。 – jcxavier

答えて

0

チェックthisTabContentFactoryはソリューションを提供します。

関連する問題