下载图像并实现gridview

时间:2012-06-05 10:25:44

标签: android gridview

我有几个字符串数组用于将文本数据从mysql服务器下载到android客户端app。我能够将标题文本(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();
} }}

0 个答案:

没有答案