3

이제 Android 프로필 프로젝트에서 JSON 클래스로 Google API의 일부 결과를 가져 오는 목록보기 목록보기가 있습니다. 이제 URL을 반환하는 TAG_ICON 변수를 통해 일부 이미지를 얻으려고하고 목록 어댑터에 직접 URL을 지정했지만 프로젝트를 실행하는 동안 이미지보기 레이아웃에서 이미지를 얻지 못하면이 문제를 해결하는 데 도움이됩니다. 여기 내 코드가URL에서 이미지를로드하여 목록보기에 추가

public class MyListActivity extends ListActivity { 

    // JSON Node names 
       private static final String TAG_CONTACTS = "results"; 
       private static final String TAG_ID = "id"; 
       private static final String TAG_NAME = "name"; 
       private static final String TAG_GENDER = "rating"; 
       private static final String TAG_REFERENCE = "reference"; 
       private static final String TAG_ICON = "icon"; 

    // contacts JSONArray 
    JSONArray result = null; 

    String url; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // url to make request 

     Intent in = getIntent(); 
     String location = in.getStringExtra("TAG_LOCATION"); 
     String type = in.getStringExtra("TAG_TYPE"); 
     url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query="+type+"+in+"+location+"&sensor=true&key=AIzaSyD38pak_katUfSR92WE2_O2b9y0JSp5htA"; 
     //} 

    new LoadData().execute(); 

    } 

class LoadData extends AsyncTask<String, String, String> 
    { 

    // Hashmap for ListView 
     ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>(); 
    protected String doInBackground(String... args) { 


     // Creating JSON Parser instance 
     JSONParser jParser = new JSONParser(); 
     // getting JSON string from URL 

     JSONObject json = jParser.getJSONFromUrl(url); 
     RatingBar myratingbar = (RatingBar)findViewById(R.id.ratingbar); 

     try { 
      // Getting Array of Contacts 
      result = json.getJSONArray(TAG_CONTACTS); 
      // looping through All Contacts 
      for(int i = 0; i < result.length(); i++){ 
       JSONObject c = result.getJSONObject(i); 

       // Storing each json item in variable 
       String id = c.getString(TAG_ID); 
       String name = c.getString(TAG_NAME); 
       String icon = c.getString(TAG_ICON); 

      // creating new HashMap 
       HashMap<String, String> map = new HashMap<String, String>(); 

       // adding each child node to HashMap key => value 
       map.put(TAG_ID, id); 
       map.put(TAG_NAME, name); 
       map.put(TAG_ICON, icon); 

       // adding HashList to ArrayList 
       contactList.add(map); 
      } 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     return null; 
      }  
     protected void onPostExecute(String file_url) { 

     /** 
     * Updating parsed JSON data into ListView 
     * */ 
     ListAdapter adapter = new SimpleAdapter(MyListActivity.this, contactList, 
       R.layout.listview_item_row, 
       new String[] {TAG_ICON,TAG_NAME}, new int[] { 
         R.id.imgIcon,R.id.txtTitle}); 

     setListAdapter(adapter); 

     // selecting single ListView item 
     ListView lv = getListView(); 

     // Launching new screen on Selecting Single ListItem 
     lv.setOnItemClickListener(new OnItemClickListener() { 


      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 

       // Starting new intent 
       Intent in = new Intent(getApplicationContext(), ProfileViewActivity.class); 
       startActivity(in); 

      } 
     }); 

     } 

} 
} 

답변

1

자바 파일에 사용자 정의 webview 요소를 사용하고 URL을 설정하십시오.

WebView webview = (WebView)findViewById(R.id.webview); 
webview.getSettings().setJavaScriptEnabled(true); 
webview.loadUrl(getString(R.URL.myurl)); 
관련 문제