我总是对 item.add 和方法设置列表有问题
public class WeatherMainActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weather_main);
ListView List = (ListView)findViewById(R.id.listView1);
InputStream is = null;
String result="";
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.4/www/base_de_donnee_stage/script.php");
List<NameValuePair> nameValue= new ArrayList<NameValuePair>();
httppost.setEntity(new UrlEncodedFormEntity(nameValue));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}
catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//paring data
int fd_temp;
String fd_name;
String fd_desc;
try{
JSONArray jArray = new JSONArray(result);
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
fd_name=json_data.getString("nom_ville");
fd_temp=json_data.getInt("temperature");
fd_desc=json_data.getString("description");
List<NameValuePair> items;
items.add("la ville:"+fd_name+"la tempurature"+fd_temp+"le climat"+fd_desc);
}
}
catch(JSONException e1){
Toast.makeText(getBaseContext(), ",hdsjh", Toast.LENGTH_LONG).show();
}catch (ParseException e1){
e1.printStackTrace();
}
}
private void setuplist(){
list.setAdapter(new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1,items));
}
}