3

现在我正在处理一个 android 项目,我有一个列表视图,该列表视图通过 JSON 类从 Google API 获取一些结果。现在我正在尝试通过返回 URL 的 TAG_ICON 变量获取一些图像,并且我直接将 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);

            }
        });

        }

}
}
4

1 回答 1

1

使用自定义 webview 元素并在您的 java 文件中设置 url。

WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(getString(R.URL.myurl));
于 2013-01-31T11:48:52.617 回答