안드로이드 개발 질문/답변
(글 수 45,052)
public class PRRoomFlipPage extends Activity {
private FlipViewController flipView;
ProgressDialog dialog;
public static ArrayList<PRRoomItem> PRRoomArr = new ArrayList<PRRoomItem>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new BackPR().execute("");
flipView = new FlipViewController(this);
flipView.setAdapter(new MyBaseAdapter(this));
setContentView(flipView);
}
private class BackPR extends AsyncTask<String, Integer, Long> {
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(PRRoomFlipPage.this, "", "로딩중 입니다...",
true);
if (!GlobalSetting.isConnect_Toast(PRRoomFlipPage.this)) {
cancel(true);
}
}
@Override
protected Long doInBackground(String... params) {
WebAPI api = new WebAPI();
String xml = api.PRGetXml();
Log.d("xml", "xml의 값 : " + xml);
PRRoomArr = XmlParser.PRRoomParser(xml);
Log.d("back", "xml" + String.valueOf(PRRoomArr.size()));
if (PRRoomArr.size() == 0) {
dialog.dismiss();
finish();
} else {
for (int i = 0; i < PRRoomArr.size(); i++) {
Log.d("parsing",
PRRoomArr.get(i).title + " / "
+ PRRoomArr.get(i).bigimg + " / "
+ PRRoomArr.get(i).category);
}
Log.d("parsing", GlobalSetting.result_code + " / "
+ GlobalSetting.msg);
dialog.dismiss();
}
return null;
}
@Override
protected void onPostExecute(Long result) {
super.onPostExecute(result);
}
}
@Override
protected void onResume() {
super.onResume();
flipView.onResume();
}
@Override
protected void onPause() {
super.onPause();
flipView.onPause();
}
private static class MyBaseAdapter extends BaseAdapter {
private static List<Data> IMG_DESCRIPTIONS = new ArrayList<Data>();
static {
Log.d("back", "flip" + String.valueOf(PRRoomArr.size()));
// for (int i = 0; i < PRRoomArr.size(); i++) {
// IMG_DESCRIPTIONS.add(new
// Data("Pokhara","pokhara.jpg","http://en.wikipedia.org/wiki/Pokhara","<b>Pokhara Sub-Metropolitan City</b> is the second largest city of Nepal with approximately 250,000 inhabitants and is situated about 200 km west of the capital Kathmandu."));
// }
Log.d("back", "flip 왜안나오지");
IMG_DESCRIPTIONS
.add(new Data(
"Drepung Monastery",
"drepung_monastery.jpg",
"<b>Drepung Monastery</b>, located at the foot of Mount Gephel, is one of the \"great three\" Gelukpa university monasteries of Tibet."));
IMG_DESCRIPTIONS
.add(new Data(
"Sera Monastery",
"sera_monastery.jpg",
"<b>Sera Monastery</b> is one of the 'great three' Gelukpa university monasteries of Tibet, located 1.25 miles (2.01 km) north of Lhasa."));
IMG_DESCRIPTIONS
.add(new Data(
"Samye Monastery",
"samye_monastery.jpg",
"<b>Samye Monastery</b> is the first Buddhist monastery built in Tibet, was most probably first constructed between 775 and 779 CE."));
IMG_DESCRIPTIONS
.add(new Data(
"Tashilunpo Monastery",
"tashilunpo_monastery.jpg",
"<b>Tashilhunpo Monastery</b>, founded in 1447 by Gendun Drup, the First Dalai Lama, is a
}
private LayoutInflater inflater;
private MyBaseAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return IMG_DESCRIPTIONS.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View layout = convertView;
if (convertView == null)
layout = inflater.inflate(R.layout.prroom_detail, null);
final Data data = IMG_DESCRIPTIONS.get(position);
TextView titleView = (TextView) layout.findViewById(R.id.titlep);
titleView.setText(AphidLog.format("%d. %s", position, data.titlep));
ImageView photoView = (ImageView) layout.findViewById(R.id.photop);
photoView.setImageBitmap(IO.readBitmap(inflater.getContext()
.getAssets(), data.imageFilenamep));
TextView textView = (TextView) layout
.findViewById(R.id.descriptionp);
textView.setText(Html.fromHtml(data.descriptionp));
return layout;
}
private static class Data {
public String titlep;
public String imageFilenamep;
public String descriptionp;
private Data(String titlep, String imageFilenamep,
String descriptionp) {
this.titlep = titlep;
this.imageFilenamep = imageFilenamep;
this.descriptionp = descriptionp;
}
}
}
}
소스인데.. 중요한게..
파싱이 끝났을때 ArrayList Size는 정상적으로 나오고 파싱도잘되는데.
아래 부분에 빨간줄쳐있는데에서는 어레이 사이즈가 제대로 안나옵니다.
제생각에는 파싱이되는동안 저 setAdapter하는 클래스도 동시에 실행되서 그러는거 같은데
어떻게 방법이없을까요....ㅠㅠㅠㅠ
doInBackGround 동작이 끝난 뒤에 onPostExecute() 에서 해당 부분을 처리하면 되지 않을까요?