1
나는 DB에서 이미지 + 텍스트를 가져 와서 gridview.i.e에 표시했습니다. gridview의 각 항목은 하나의 이미지와 하나의 텍스트로 구성되어 있습니다. 잘 작동합니다. 그러나 안드로이드에서 각 gridview 항목의 경계를 개별적으로 설정하는 방법을 알고 싶습니다. 어떻게해야합니까? 제가 DB에서 검색 한 데이터를 저장하려면 여기를 CustomListAdapter을 사용안드로이드에있는 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 코드는
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
동일한 문제가 있습니다 ..... 각 격자 주위에 간단한 사각형을 넣는 방법은 무엇입니까? – thej
문제를 해결하셨습니까? 공유 할 수 있습니까? – user1781367