gpt4 book ai didi

java - 在 Android 的 GridView 中放置图像(从 URL 加载)和编辑文本框

转载 作者:行者123 更新时间:2023-12-02 06:53:02 25 4
gpt4 key购买 nike

请有人帮我在 Android GridView 中放置一个图像(从 URL 在 GridView 中显示图像)和 Edittextbox

这是我的 GridView xml 布局:

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

下面是我用来填充网格的代码,它工作正常,我需要放置来自 url 和 edittextbox 的图像:

    super.onCreate(savedInstanceState); 
setContentView(R.layout.order_details);
File yourFile = new File("/sdcard/json/orderdetails.txt");
FileInputStream stream = null;
try {
stream = new FileInputStream(yourFile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String jString = "";
try {
FileChannel fc = stream.getChannel();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());


/* Instead of using default, pass in a decoder.*/
jString = Charset.defaultCharset().decode(bb).toString();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
try {
stream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

String fileContent=jString;
JSONObject jobj = null;
JSONObject jobj1 = null;
try {
jobj = new JSONObject(fileContent);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {

JSONArray ja = jobj.getJSONArray("ORDERDETAILS");

listContent.add("ITEM NAME");
listContent.add("ORDER QUANTITY");
listContent.add("PRICE");
listContent.add("PREFERED SHOP");
for(int i=0; i<ja.length(); i++){
String ORDERDETAILS = ja.getString(i);
System.out.println(ORDERDETAILS);
jobj1 = new JSONObject(ORDERDETAILS);
String ITEMNAME = jobj1.getString("ITEMNAME");
listContent.add(ITEMNAME);
System.out.println(ITEMNAME);
String ORDERQUANTITY = jobj1.getString("ORDERQUANTITY");
listContent.add(ORDERQUANTITY);
System.out.println(ORDERQUANTITY);
String PRICE = jobj1.getString("PRICE");
listContent.add(PRICE);
System.out.println(PRICE);
String SHOPNAME = jobj1.getString("SHOPNAME");
System.out.println(SHOPNAME);
listContent.add(SHOPNAME);

}

} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
gridView = (GridView)findViewById(R.id.order_details_grid);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,listContent);
gridView.setAdapter(adapter);
// gridView.setAdapter(new ImageAdapter(this));

}

这是我从中获取 json 数据的 json 文件:

           {
"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": ""
}
]
}

最佳答案

检查下面的链接并下载示例应用程序,它将对您有所帮助

https://github.com/nostra13/Android-Universal-Image-Loader

关于java - 在 Android 的 GridView 中放置图像(从 URL 加载)和编辑文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17787009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com