1

このコードを使用して、アレイアダプタを使用して**データを設定することにより、特定の場所の近くの場所をロードします。私が直面している問題は2つあります。1。データがロードされてもスピナーが停止しない。(スピナーはないはずです。しかし、これに関しては、Fragmentがどのように機能するのかわかりません。)

  1. アクティビティの速度が低下しないように、場所を取得するためにAsyncTaskを実装します。私が直面している小さな問題は次のとおりです。ユーザーが場所を変更したときに、新しい日付でユーザーに通知(ビューを更新)するにはどうすればよいですか。ユーザーが歩いていると仮定しましょう。したがって、緯度/経度が変更されます。では、onChangeNotify()を使用して、リストの値を変更するにはどうすればよいですか。

    パブリッククラスFragmentMapはListFragmentを拡張します{

        ArrayList<Place> places = new ArrayList<Place>();
        //List<String> val = new List<String>()
        //@InjectView(R.id.explorePlacesListView) ListView placesListView;
        ListView listView;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
    
        }
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
    
    
                ListView listView = (ListView) getActivity().findViewById(R.id.explorePlacesListView);
            getPlaces();
    
            PlacesAdapter placesAdapter = new PlacesAdapter(getActivity(),R.layout.user_list_item, places);
            listView.setAdapter(placesAdapter);
        }
    
    
    
        public void getPlaces(){
    
             URL yahoo;
             String key,latitude,longitude;
             key = "AIzaSyAZgD01sj3jssaYCmkLL8c7Z4qPTEdt6xU";
             latitude = "37.77264";
             longitude ="-122.409915";
            try {
    
                yahoo = new URL("https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&sensor=false&key=AIzaSyB2SGEmOLDGB_f0bp1PGTjQqTw2VuDcaM8");
                URLConnection yc = yahoo.openConnection();
                BufferedReader in = new BufferedReader(
                                        new InputStreamReader(
                                        yc.getInputStream()));
                String inputLine;
                String jsonLine = new String();
                while ((inputLine = in.readLine()) != null) {
                        Log.d("inputLine",inputLine);
    
                        jsonLine = jsonLine + inputLine;
            }
                in.close();
                Object jsonResponse = parseResponse(jsonLine);
                parseJSONPlaces((JSONObject)jsonResponse);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
    
        protected Object parseResponse(String responseBody) throws JSONException {
            return new JSONTokener(responseBody).nextValue();
        }
    
     private void parseJSONPlaces(JSONObject json){
    
         try {
        JSONArray jsonArray =   json.getJSONArray("results");
    
        for (int j = 0; j < json.length(); j++) {
    
            Place place = new Place();
    
    
            place.name = jsonArray.getJSONObject(j).getString("name");
            place.icon = jsonArray.getJSONObject(j).getString("icon");
           // JSONObject locationObject = jsonArray.getJSONObject(j).getJSONObject("location");
           // place.latitude = locationObject.getString("latitude");
           // place.longitude = locationObject.getString("longitude");
            Log.d("name",place.name);
    
            places.add(place);
        }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
          if(json.optJSONObject("results") != null){
    
    
            }
    
    
    
     }
    
4

1 に答える 1

2

あなたのコードには、私には少し奇妙に見えることがいくつかあります。

setListAdapter()アダプターをListFragmentの内部ListViewにバインドするwhichを呼び出すことはありません。代わりに、別のListViewをフェッチして、そのアダプターにアダプターを設定します。これがおそらく、リストにデータが表示されず、代わりに進行状況インジケーターが表示される理由です。

2番目の質問を理解できるかどうかはわかりませんが、UIの更新をAsychTaskのonPostExecuteメソッドに配置する必要があります。

于 2012-08-03T13:15:22.790 に答える