2013-08-02 72 views
0

我想更新屏幕哪個imagebutton兩個按下新的值fromurland更新scren什麼是ido?請幫幫我。當我按img2按鈕屏幕不更新幫助請如何更新parseJSONData();當img2點擊時功能機智新的網址?如何刷新屏幕哪個按鈕按下?

public class fourthscreen extends Activity 
     TextView Breakfast,Lunch,Supper; 
     String SelectMenuAPI; 
String url; 

      FourthcreenAdapter fthadapter; 


static ArrayList<Long> Category_ID = new ArrayList<Long>(); 
static ArrayList<String> Category_name = new ArrayList<String>(); 


     public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fourthscreen); 

      url=Utils.SelectMenuAPI; 

    listMainMenu = (ListView) findViewById(R.id.listfourthscrMenu); 
    date_today = (TextView) findViewById(R.id.date_today); 
    Breakfast = (TextView) findViewById(R.id.txtfth1); 
    Lunch = (TextView) findViewById(R.id.txtfth2); 
    Supper = (TextView) findViewById(R.id.txtfth3); 
      fthadapter = new FourthcreenAdapter(fourthscreen.this); 
    ImageView img1 = (ImageView) findViewById(R.id.imgfourth1); 
    ImageView img2 = (ImageView) findViewById(R.id.imgfourth2); 
    ImageView img3 = (ImageView) findViewById(R.id.imgfourth3); 
     parseJSONData(); 

     listMainMenu.setAdapter(fthadapter); 



      img2.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      url=Utils.SelectMenuAPI2; 
      parseJSONData(); 



     } 
    }); 

       } 


void clearData(){ 
     Category_ID.clear(); 
     Category_name.clear(); 

    } 






        } 


public void parseJSONData(){ 
     // CategoryAPI = Utils.CategoryAPI+"?accesskey="+Utils.AccessKey; 

     SelectMenuAPI = url; 

      clearData(); 


      try { 

       HttpClient client = new DefaultHttpClient(); 
       HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000); 
       HttpConnectionParams.setSoTimeout(client.getParams(), 15000); 
       HttpUriRequest request = new HttpGet(SelectMenuAPI); 
       HttpResponse response = client.execute(request); 
       InputStream atomInputStream = response.getEntity().getContent(); 
       BufferedReader in = new BufferedReader(new InputStreamReader(atomInputStream)); 

       String line; 
       String str = ""; 
       while ((line = in.readLine()) != null){ 
        str += line; 
       } 


        JSONObject json = new JSONObject(str); 
        JSONArray data = json.getJSONArray("worldpopulation"); 

        for (int i = 0; i < data.length(); i++) { 
         JSONObject object = data.getJSONObject(i); 

        // JSONObject category = object.getJSONObject("Category"); 

         Category_ID.add(Long.parseLong(object.getString("rank"))); 
         Category_name.add(object.getString("name")); 
        // Category_image.add(object.getString("url")); 
         Log.d("Category name", Category_name.get(i)); 

        } 


      } catch (MalformedURLException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
      // IOConnect = 1; 
       e.printStackTrace(); 
      } catch (JSONException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
+0

如何更新listview與新的url當img2點擊?????? – user2644835

回答

0

如果你想查看某個ImageView已被點擊:

這個貼在ImageViews的塔布局:

android:onClick="onClickFunction" 

然後創建這個功能,所以看起來像這樣:

public void onClickFunction(View v) { 

    swith (v.getid()){ 
    case R.id.imgfourth1: 
     //do something 
     break; 
    case R.id.imgfourth2: 
     //do something 
     break; 
    case R.id.imgfourth3: 
     //do something 
     break; 

    } 
} 

然後,根據點擊的視圖,在doInBackground()方法中啓動一個帶有parseJSONData()的AsyncTask。

0

您應該通知您的陣列適配器,它用於在listview中處理數據。

0

你的HTTP請求不應放置在主線程,FourthcreenAdapter哪裏這個類的代碼,獲得數據,然後調用適配器的notifyDataSetChanged()方法