0
이것은 webservice의 json 형식입니다. { "result": [{ "id": "1", "category": "Rumah sakit", "hospital.png"}]}Android 앱 : 애플리케이션에서 웹 서비스의 이미지를 가져 오는 방법은 무엇입니까?
여기에 안드로이드 코드는 다음과 같습니다
공용 클래스 ARPublicFacilitiesActivity는 활동 {
public static int PILIHAN = 0;
private ProgressDialog waitDialog;
private LinearLayout layout;
private String JsonKategori = "";
private ImageLoader imgLoader;
public static String image[];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
setContentView(R.layout.menudinamis);
layout = (LinearLayout) findViewById(R.id.layout);
waitDialog = ProgressDialog.show(ARPublicFacilitiesActivity.this, "",
"Download category ...");
waitDialog.setIcon(R.drawable.iconarpf);
waitDialog.show();
new UnduhCategoryTask().execute();
}
class UnduhCategoryTask extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... arg0) {
JsonKategori = HTTPConnection.openUrl(HTTPConnection.host
+ "category.php");
System.out.println("Data : " + JsonKategori);
return null;
}
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
waitDialog.dismiss();
initButton();
}
}
public void initButton() {
imgLoader = new ImageLoader(this);
// memparsing json
try {
JSONObject jo = new JSONObject(JsonKategori);
JSONArray ja = jo.getJSONArray("result");
int id = 0;
image = new String[ja.length()];
LinearLayout ly[] = new LinearLayout[2];
// DrawableManager dm = new DrawableManager();
for (int x = 0; x < ly.length; x++) {
ly[x] = new LinearLayout(this);
ly[x].setOrientation(LinearLayout.VERTICAL);
ly[x].setPadding(5, 5, 5, 5);
ly[x].setGravity(Gravity.CENTER_VERTICAL);
}
for (int x = 0; x < ja.length(); x++) {
JSONObject joj = ja.getJSONObject(x);
image[x] = joj.getString("image");
ImageView img = new ImageView(this);
img.setPadding(5, 5, 5, 2);
img.setMinimumHeight(96);
img.setMinimumWidth(96);
img.setMaxHeight(96);
img.setMaxWidth(96);
final String nilai = joj.getString("id") + "";
img.setTag(HTTPConnection.urlPicture
+ joj.getString("image"));
imgLoader.DisplayImage(HTTPConnection.urlPicture
+ joj.getString("image"),this, img);
img.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
PILIHAN = Integer.parseInt(nilai);
startActivity(new Intent(
ARPublicFacilitiesActivity.this, MixView.class));
}
});
ly[id].addView(img);
TextView txt = new TextView(this);
txt.setText(joj.getString("category"));
txt.setTextColor(Color.GRAY);
txt.setGravity(Gravity.CENTER_HORIZONTAL);
ly[id].addView(txt);
if (ja.length() % 2 == 0) {
if (x == ((ja.length()/2) - 1)) {
layout.addView(ly[id]);
++id;
}
} else {
if (x == (ja.length()/2)) {
layout.addView(ly[id]);
++id;
}
}
}
layout.addView(ly[id]);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
내가 이상이 스크립트를 실행, 카테고리 제목을 확장하고 이미지가 성공을 표시합니다. 문제는 웹 서비스에서 내 이미지가 아닌 이미지로 표시되지만 안드로이드 기본 아이콘입니다. 웹 서비스에서 이미지 크기를 조정하려고했지만 여전히 작동하지 않습니다.
제발 도와주세요.
고마워요.