Java 在Android的网格视图中放置图像(从URL加载)并编辑文本框
有人请帮我在Android网格视图中放置一个图像(从URL在网格视图中显示图像)和Edittextbox 这是我的网格视图xml布局:Java 在Android的网格视图中放置图像(从URL加载)并编辑文本框,java,android,android-layout,android-gridview,Java,Android,Android Layout,Android Gridview,有人请帮我在Android网格视图中放置一个图像(从URL在网格视图中显示图像)和Edittextbox 这是我的网格视图xml布局: <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" /> <GridView android:id="@+id/order_details_grid" android:layout_width="fill_
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:id="@+id/order_details_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="4"
android:columnWidth="100px"
android:stretchMode="columnWidth"
android:gravity="center"/>
</LinearLayout>
检查下面的链接并下载示例应用程序,它将帮助您
不要使用
ArrayAdapter
,创建一个扩展BaseAdapter
的类来创建您自己的自定义适配器
然后在getView方法中,为网格的每个单元格膨胀xml布局(您可以在其中放置TextView、EditText、图像或任何您想要的内容)
重写的getView方法如下所示:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View cell;
if(convertView==null){
cell= new View(context);
//create a file "cell_layout.xml" in your layout folder to define the layout for each cell
cell= layoutInflater.inflate(R.layout.cell_layout, null);
}else{
cell= (View)convertView;
}
ImageView imageView = (ImageView)cell.findViewById(R.id.image);
imageView.setImageBitmap(bitmap[position]);
TextView textView = = (TextView)cell.findViewById(R.id.text);
textView .setText("hello world from gridView");
return cell;
}
可以找到一个更完整的示例,但通过谷歌搜索“自定义适配器”可以找到很多示例
从url加载图片的问题是另一个话题,Arman给出的答案似乎不错。我建议您看看,尤其是我经常使用的。您将图像设置为imageview,然后刷新视图:)如何操作?如何将图像视图(图像url)设置为网格?
{
"ORDERDETAILS": [
{
"ITEMNAME": "APPLE-LAPTOP",
"ORDERQUANTITY": "35",
"PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403",
"SHOPIMAGEURL": "http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg"
},
{
"ITEMNAME": "ASUS-NOTEBOOK",
"ORDERQUANTITY": "35",
"PRICE": "3500 DHMS",
"SHOPNAME": "Indico Icon Kits 403",
"SHOPIMAGEURL": ""
},
{
"ITEMNAME": "DELL-LAPTOP",
"ORDERQUANTITY": "35",
"PRICE": "9500 DHMS",
"SHOPNAME": "Indico Icon Kits 403",
"SHOPIMAGEURL": ""
}
]
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View cell;
if(convertView==null){
cell= new View(context);
//create a file "cell_layout.xml" in your layout folder to define the layout for each cell
cell= layoutInflater.inflate(R.layout.cell_layout, null);
}else{
cell= (View)convertView;
}
ImageView imageView = (ImageView)cell.findViewById(R.id.image);
imageView.setImageBitmap(bitmap[position]);
TextView textView = = (TextView)cell.findViewById(R.id.text);
textView .setText("hello world from gridView");
return cell;
}