0
안드로이드는 내가 doInBackground
방법에 주석을 얻을 수있는 JSON 함수를 사용하는 AsyncTask
있습니다. 그런 다음 그 다음 IS setListAdapter
에 문자열을 배치 String[]
에 JSONArray
을 배치 onPostExecute
에 의견의 배열을 보냅니다. 코드가 충돌하지 않고 모든 것이 제대로 작동하는 것처럼 보이지만 설명은 Activity
안에 표시되지 않습니다.댓글 -
class loadComments extends AsyncTask<JSONObject, String, JSONObject> {
@Override
protected JSONObject doInBackground(JSONObject... params) {
final JSONObject json2 = CollectComments.collectComments(usernameforcomments,
offsetNumber);
return json2;
}
@Override
protected void onPostExecute(JSONObject json2) {
try {
if (json2.getString(KEY_SUCCESS) != null) {
registerErrorMsg.setText("");
final String res2 = json2.getString(KEY_SUCCESS);
if (Integer.parseInt(res2) == 1) {
final JSONArray array = json2.getJSONArray(KEY_COMMENT);
final String comments[] = new String[array.length()];
for (int i = 1; i <= array.length(); i++) {
comments[i] = array.getString(i);
}
setListAdapter(new ArrayAdapter<String>(DashboardActivity.this,
R.layout.list_item, R.id.label, comments));
}// end if key is == 1
else {
// Error in registration
registerErrorMsg.setText(json2.getString(KEY_ERROR_MSG));
}// end else
}// end if
} // end try
catch (final JSONException e) {
e.printStackTrace();
}// end catch
}
}
new loadComments().execute();
활동에 대한 내 XML이
<RelativeLayout
android:id="@+id/dashboardRelative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:orientation="vertical" >
<Button
android:id="@+id/btnPost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/dashboard_post"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:text="@string/post"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/commentSection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btnPost"
android:layout_margin="20dip"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<!-- Error message -->
<TextView
android:id="@+id/collectComment_error"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/commentSection"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dip"
android:textColor="#e30000"
android:textStyle="bold" />
</RelativeLayout>
시험 후 응용 프로그램 디버깅을. 그것이 원하는대로 작동을 멈추는 지점을보십시오. –