tc199604
tc199604
2017-10-30 12:56

安卓问题,代码如下:想显示一个listView。但是跳转到合格activity什么都不显示。

  • android

package com.coolweather.app.activity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.coolweather.app.R;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebIconDatabase.IconListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class Future extends Activity{

private ListView lvFur;
private static List list= new ArrayList();
private TextView tvTest;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.furture);
lvFur = (ListView) findViewById(R.id.listView1);
WeatherActivity wa = new WeatherActivity();
handleWeatherResponse(wa.result);
lvFur.setAdapter(adapter);

}
public BaseAdapter adapter = new BaseAdapter() {

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = LayoutInflater.from(Future.this);
        if(convertView==null){
            convertView = inflater.inflate(R.layout.item, null);
            TextView tv_data = (TextView) convertView.findViewById(R.id.textView_data);
            TextView tv_wendu = (TextView) convertView.findViewById(R.id.textView_wendu);
            ImageView iv_head = (ImageView)convertView.findViewById(R.id.imageView_head);
            tv_data.setText(list.get(position).getCityname()+list.get(position).getDate());
            tv_wendu.setText(list.get(position).getWeather()+list.get(position).getTmper());
            ViewHolder vh= new ViewHolder(tv_data,tv_wendu);
            convertView.setTag(vh);
        }else{
            ViewHolder vh = (ViewHolder) convertView.getTag();

            vh.tv_data.setText(list.get(position).getCityname()+list.get(position).getDate());
            vh.tv_wendu.setText(list.get(position).getWeather()+list.get(position).getTmper());
        }
        return convertView;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }
};
public class ViewHolder{
    private TextView tv_data;
    private TextView tv_wendu;
    //private ImageView iv_head;
    public TextView getTv_data() {
        return tv_data;
    }
    public void setTv_data(TextView tv_data) {
        this.tv_data = tv_data;
    }
    public TextView getTv_wendu() {
        return tv_wendu;
    }
    public void setTv_wendu(TextView tv_wendu) {
        this.tv_wendu = tv_wendu;
    }

// public ImageView getIv_head() {
// return iv_head;
// }
// public void setIv_head(ImageView iv_head) {
// this.iv_head = iv_head;
// }

public ViewHolder(TextView tv_data, TextView tv_wendu) {
super();
this.tv_data = tv_data;
this.tv_wendu = tv_wendu;
//this.iv_head = iv_head;
}

}
//解析joson数据
public static void handleWeatherResponse(String response) {
    try {
        JSONArray root = new JSONArray(response);
        for(int i = 0;i < root.length();i++){
            JSONObject item = root.getJSONObject(i);
            String date = item.getString("days");
            String week = item.getString("week");
            String weather = item.getString("weather");
            String cityname = item.getString("citynm");
            String tmp = item.getString("temperature");
            list.add(new Furweather(date+week,weather,cityname, tmp));
        }
    }catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}
class Furweather{
private String date;
private String weather;
private String cityname;
private String tmper;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getWeather() {
return weather;
}
public void setWeather(String weather) {
this.weather = weather;
}
public String getCityname() {
return cityname;
}
public void setCityname(String cityname) {
this.cityname = cityname;
}
public String getTmper() {
return tmper;
}
public void setTmper(String tmper) {
this.tmper = tmper;
}
public Furweather(String date, String weather, String cityname,
String tmper) {
super();
this.date = date;
this.weather = weather;
this.cityname = cityname;
this.tmper = tmper;
}

}

其中result是从另一个activity中传过来的joson数据。现在打开这个activity没有显示。求大神指出是哪里的问题。。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐

换一换