碎片微调器不';不要停在Android中
我使用此代码通过使用阵列适配器设置**数据来加载任何特定位置的附近位置。我面临两个问题: 1.即使在加载数据后,微调器也不会停止。(应该没有旋转器。但我不确定Fragment在这方面是如何实现的。)碎片微调器不';不要停在Android中,android,Android,我使用此代码通过使用阵列适配器设置**数据来加载任何特定位置的附近位置。我面临两个问题: 1.即使在加载数据后,微调器也不会停止。(应该没有旋转器。但我不确定Fragment在这方面是如何实现的。) 我将实现AsyncTask来获取位置,这样就不会减慢活动。我面临的小问题是:当用户更改位置时,我如何通知用户(更新视图)新的日期。让我们假设用户正在行走。因此,lat/lon将发生变化。那么,如何使用onChangeNotify()并更改列表的值呢 公共类FragmentMap扩展了ListFrag
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){
}
}
ArrayList places=new ArrayList();
//List val=新列表()
//@InjectView(R.id.explorePlacesListView)列表视图placesListView;
列表视图列表视图;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
@凌驾
已创建ActivityState上的公共无效(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
ListView ListView=(ListView)getActivity().findViewById(R.id.explorePlacesListView);
getPlaces();
PlacesAdapter PlacesAdapter=新的PlacesAdapter(getActivity(),R.layout.user\u list\u项,places);
setAdapter(placesAdapter);
}
公众地方(){
雅虎网址;
字符串键,纬度,经度;
key=“AIZASYAZGD01SJ3JSSAYCMKLL8C7Z4QPTED6XU”;
纬度=“37.77264”;
经度=“-122.409915”;
试一试{
yahoo=新URL(“https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522151.1957362&radius=500&sensor=false&key=AIzaSyB2SGEmOLDGB_f0bp1PGTjQqTw2VuDcaM8”);
URLConnection yc=yahoo.openConnection();
BufferedReader in=新的BufferedReader(
新的InputStreamReader(
yc.getInputStream());
字符串输入线;
String jsonLine=新字符串();
而((inputLine=in.readLine())!=null){
Log.d(“inputLine”,inputLine);
jsonLine=jsonLine+inputLine;
}
in.close();
对象jsonResponse=parseResponse(jsonLine);
parseJSONPlaces((JSONObject)jsonResponse);
}捕获(格式错误){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(JSONException e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
受保护对象parseResponse(String ResponseBy)抛出JSONException{
返回新的JSONTokener(responseBody).nextValue();
}
私有void parseJSONPlaces(JSONObject json){
试一试{
JSONArray JSONArray=json.getJSONArray(“结果”);
for(int j=0;j
你的代码中有一些东西对我来说有点奇怪 您从未调用将适配器绑定到ListFragment内部ListView的
setListAdapter()
。相反,您正在获取另一个ListView并将适配器设置为该ListView。这可能就是列表中不显示数据的原因,您将使用进度指示器
我不确定我是否理解您的第二个问题,但您应该将UI更新放在AsychTask的onPostExecute方法中。您说的“微调器”是指“忙”指示器吗不,我指的是一个微调器。没有文本。什么都没有。只是文本旁边的一个旋转的东西。不,实际上,你不是在说微调器。android中的微调器是一个下拉列表选择器小部件(这就是为什么我问这个问题,因为你的问题与android微调器没有任何关系)。你说的是进度条,不幸的是,我没有机会使用进度条,所以我对进度条一无所知。是的。我弄错了。那么,我是否必须跨过列表片段才能插入此列表?你已经在扩展ListFragment,所以我想你自己的listView是不必要的。请查看和谷歌的一些示例例如,如果您想提供自己的自定义视图,请查看OnCreateViews。问题是示例处理的是列表适配器,而不是数组适配器。我想使用数组适配器将数据推送到列表视图中。我链接的示例实际上使用了ArrayAdapter。