http://developer.android.com/resources/tutorials/views/hello-gridview.html 上記のコード例では、各画像にテキストを追加します。どうすればいいですか?Android:Gridviewでは、画像にラベルを追加する方法
0
A
答えて
0
次のリンク(アイコンとテキストとGridViewのは)あなたに役立つことができ
0
1 - あなたはGridViewコントロール内の各アイテムに使用するレイアウトを作成し、イメージビューとテキストビューを含む。
2 - あなたのxmlレイアウトであなたのGridViewを作成します。(主な活動)
3- ImageAdapterクラス(またはメソッド)を追加し、写真のメインリストのデータをバインドするために使用されます。
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.panoramio;
import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
* Adapter used to bind data for the main list of photos
*/
public class ImageAdapter extends BaseAdapter {
/**
* Maintains the state of our data
*/
private ImageManager mImageManager;
private Context mContext;
private MyDataSetObserver mObserver;
/**
* Used by the {@link ImageManager} to report changes in the list back to
* this adapter.
*/
private class MyDataSetObserver extends DataSetObserver {
@Override
public void onChanged() {
notifyDataSetChanged();
}
@Override
public void onInvalidated() {
notifyDataSetInvalidated();
}
}
public ImageAdapter(Context c) {
mImageManager = ImageManager.getInstance(c);
mContext = c;
mObserver = new MyDataSetObserver();
mImageManager.addObserver(mObserver);
}
/**
* Returns the number of images to display
*
* @see android.widget.Adapter#getCount()
*/
public int getCount() {
return mImageManager.size();
}
/**
* Returns the image at a specified position
*
* @see android.widget.Adapter#getItem(int)
*/
public Object getItem(int position) {
return mImageManager.get(position);
}
/**
* Returns the id of an image at a specified position
*
* @see android.widget.Adapter#getItemId(int)
*/
public long getItemId(int position) {
PanoramioItem s = mImageManager.get(position);
return s.getId();
}
/**
* Returns a view to display the image at a specified position
*
* @param position The position to display
* @param convertView An existing view that we can reuse. May be null.
* @param parent The parent view that will eventually hold the view we return.
* @return A view to display the image at a specified position
*/
public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
// Make up a new view
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.image_item, null);
} else {
// Use convertView if it is available
view = convertView;
}
PanoramioItem s = mImageManager.get(position);
ImageView i = (ImageView) view.findViewById(R.id.image);
i.setImageBitmap(s.getBitmap());
i.setBackgroundResource(R.drawable.picture_frame);
TextView t = (TextView) view.findViewById(R.id.title);
t.setText(s.getTitle());
t = (TextView) view.findViewById(R.id.owner);
t.setText(s.getOwner());
return view;
}
}
4-、私の悪い英語のためBaseAdapter
MyGridView = (GridView)findViewById(R.id.MyGridView);
MyGridView .setAdapter(new ImageAdapter(this));
申し訳から延びるImageAdapterクラスであなたのGridViewを記入し、それはあなたを助け願っています。
+0
Anass、Sorry ...上記のコードの画像にテキスト(ラベル)を設定していますか? – user893195
関連する問題
- 1. 分類用の画像データセットにラベルを追加する方法は?
- 2. スウィフト360画像:パノラマ画像にボタンを追加する方法
- 3. Jenkins - 追加フォルダをサブフォルダに追加する方法。画像
- 4. 別の方法でリソースに画像を追加する方法
- 5. テーブルセルのカスタマイズ。画像とラベルの追加
- 6. iPhone dev:画像に重複するラベルを追加する
- 7. ScrollViewに画像を動的に追加する方法は?
- 8. iPadでフル画像表示画面を追加する方法
- 9. IOSでDialogViewControllerに画像付きのラベルを追加
- 10. ドロップダウンメニューで画像イベントを追加する方法は?
- 11. ListViewで画像をサブアイテムとして追加する方法は?
- 12. 親の拡大リストビューに画像を追加する方法は?
- 13. WPギャラリーに画像をアップロードして追加する方法は?
- 14. ReactJS:グリッドに画像を追加する方法は?
- 15. 背景画像をグリッドセルに追加する方法は?
- 16. 画像にソフトフォーカスをプログラムで追加する方法
- 17. iPhoneアプリでUINavigationBarに画像を追加する方法
- 18. ライトボックスで画像を動的に追加する方法
- 19. レールにラベルを貼り付けた後に画像を追加
- 20. Android:GridViewにセルを動的に追加できますか?
- 21. MenuStripItemsを画像と共に動的に追加する方法
- 22. ツールバーの戻るボタンを画像ビューに追加する方法
- 23. 画像の上に番号ラベルを追加
- 24. 別の画像の上に画像を追加するには?
- 25. 画像に画像フレームを追加するには?
- 26. Android:enum.values()ではなく、スピナーにenumラベルを追加する方法
- 27. Ajaxを使ってMySQLに画像を追加する方法
- 28. フレームレイアウトの画像とテキストにグラデーションを追加する方法を
- 29. iosの円形フレームで画像を追加する方法
- 30. プログラムで追加した画像サイズを変更する方法
リンクはもう機能していません。 – WeirdElfB0y