我有几个字符串数组,用于将文本数据从 mysql 服务器下载到 android 客户端应用程序。我能够将标题文本(F_NAME)显示为 listview。如何为保存在服务器上单独文件夹中的每个文本下载相应的图像(该文件夹的正确路径可用,让它成为我的网址)。我需要将所有图像以及来自 F_NAME[] 的标题名称显示为 gridview。我应该进行哪些更改?请编辑我的代码并向我显示确切的代码,谢谢提前。我的 java 类和 xml 文件:
public class MainMenu extends ListActivity {
InputStream is;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String result = "";
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(my url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("log_tag", "connection success ");
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();}
catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
Toast.makeText(getApplicationContext(), "fail1", Toast.LENGTH_SHORT).show();}
try{
JSONArray jArray = new JSONArray(result);
int arrayLength=jArray.length();
String F_NAME[]=new String[arrayLength];
String F_ID[]=new String[arrayLength];
String F_AVAIL[]=new String[arrayLength];
String F_DESCP[]=new String[arrayLength];
String F_COST[]=new String[arrayLength];
for(int i=0;i<arrayLength;i++){
JSONObject json_data = jArray.getJSONObject(i);
F_ID[i]=json_data.getInt("F_ID")+"";
F_NAME[i]=json_data.getString("F_NAME");
F_DESCP[i]=json_data.getString("F_DESCP");
F_AVAIL[i]=json_data.getString("F_AVAIL");
F_COST[i]=json_data.getInt("F_COST")+"";}
setListAdapter(new ArrayAdapter<String>(this, R.layout.menu, F_NAME));
ListView lv = getListView();
lv.setTextFilterEnabled(true);lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();}});}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
Toast.makeText(getApplicationContext(), "fail"+e.toString(), Toast.LENGTH_SHORT).show();
} }}