mysql의 데이터를 이름으로 나열된 사무실 목록보기로 표시하고 목록 항목을 클릭하면 자세한 정보를 얻을 수 있습니다. 그 사무실. 이제 목록이 나타나지 않습니다. 나는 안드로이드 (2 주 전부터 시작)에 새로운 사람입니다. 그래서 어떻게 고쳐야하는지 이해할 수 없습니다. 제발 저를 도울 수 있습니까?android trough에서 목록보기로 MySQL 쿼리 결과 JSON
public class Office extends ListActivity implements OnItemClickListener{
ListView officeList;
InputStream is = null;
String result = "";
String result1 [];
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.office);
officeList = (ListView)findViewById(R.id.officeL);
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id","0"));
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.protocolliweb.com/mysqlcon.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
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();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
result1[i] = json_data.getString("nome");
}
officeList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, result1));
officeList.setOnItemClickListener(this);
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
}
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String bread = officeList.getContext().toString();
Bundle basket = new Bundle();
basket.putString("key", bread);
Intent a = new Intent(Office.this,Details.class);
a.putExtras(basket);
startActivity(a);
}
}
당신은ListActivity
에서이 작업을 수행 할 수
고마워요! 확인 목록 수정됩니다 ...하지만 어쨌든 작동하지 않습니다 ... 문제는 JSON coversion ... 어떤 팁에 대한 것? – user1099798
로깅을 사용하여'result'와'result1'의 배열 요소를 봅니다. 그것이 내가 할 수있는 유일한 방법이다. – Squonk