1
我從數據庫中檢索圖像+文本並將其顯示在gridview.i.e中。每個gridview項目包含一個圖像+一個文本。它工作正常。但我只是想知道如何設置每個gridview項目的邊界在android.How我可以做到這一點?android中的gridview項的邊框
我的代碼..
public class HomePage extends Activity {
private ArrayList<SingleElementDetails> allElementDetails=new ArrayList<SingleElementDetails>();
DBAdapter db=new DBAdapter(this);
String category, description;
String data;
String data1;
GridView gridview;
Button menu;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homepage);
menu=(Button)findViewById(R.id.menus);
menu.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
gridview=(GridView)findViewById(R.id.gridview);
TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
int mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
allElementDetails.clear();
db.open();
long id;
//id=db1.insertTitle1(category, description,r_photo);
Cursor cursor = db.getAllTitles1();
while (cursor.moveToNext())
{
SingleElementDetails single=new SingleElementDetails();
single.setDishName(cursor.getString(1));
single.setCateogry(cursor.getString(2));
single.setDescription(cursor.getString(3));
single.setImage(cursor.getBlob(4));
allElementDetails.add(single);
}
db.close();
CustomListAdapter adapter=new CustomListAdapter(HomePage.this,allElementDetails);
gridview.setAdapter(adapter);
gridview.setBackgroundResource(mGalleryItemBackground);
}
});
}
}
我用CustomListAdapter這裏從數據庫檢索數據的存儲。 我CustomListAdapter代碼...
public class CustomListAdapter extends BaseAdapter {
private ArrayList<SingleElementDetails> allElementDetails;
private LayoutInflater mInflater;
public CustomListAdapter(Context context, ArrayList<SingleElementDetails> results) {
allElementDetails = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return allElementDetails.size();
}
public Object getItem(int position) {
return allElementDetails.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = mInflater.inflate(R.layout.listview1, null);
ImageView imageview = (ImageView) convertView.findViewById(R.id.image);
TextView textview1= (TextView) convertView.findViewById(R.id.dishname_entry);
TextView textview2 = (TextView) convertView.findViewById(R.id.category_entry);
TextView textview3=(TextView)convertView.findViewById(R.id.description_entry);
textview1.setText(allElementDetails.get(position).getDishName());
textview2.setText(allElementDetails.get(position).getCategory());
if(allElementDetails.get(position).getDescription().length()>8)
textview3.setText(allElementDetails.get(position).getDescription().substring(0,8)+"...");
else
textview3.setText(allElementDetails.get(position).getDescription());
byte[] byteimage=allElementDetails.get(position).getImage();
ByteArrayInputStream imageStream = new ByteArrayInputStream(byteimage);
BitmapFactory.Options op=new BitmapFactory.Options();
op.inSampleSize=12;
Bitmap theImage= BitmapFactory.decodeStream(imageStream,null,op);
imageview.setImageBitmap(theImage);
return convertView;
}
}
我最近幾乎解決了類似的問題。你在看什麼樣的邊界?每個網格周圍都有一個簡單的矩形/正方形? – Abhijit 2012-04-11 15:01:51
我有同樣的問題.....如何把一個簡單的正方形圍繞每個網格? – thej 2012-09-07 07:56:27
你解決了這個問題嗎?你可以分享嗎? – user1781367 2013-05-22 12:38:22