안녕하세요.
일단 저는 기본이 부족해서 제가 해놓고 뭐가 잘 못 됐는지를 잘 모르는 편입니다.
그 때 그 때 구글링해서 해보는 쪽입니다. 그래서 걱정되는게 코드가 많이 안 좋을꺼고 보시기도 힘들지도
모릅니다. 넓은 아량으로 양해해주세요. 죄송합니다.
우선 문제는 open api에서 값을 가져왔는데
그냥 Arraylist<String>으로 값을 가져와서 ArrayAdapter에 집어넣으면 값 전체가 일반적인 그냥
리스트뷰에 제대로 들어가는것 까지는 확인이 됩니다.
그런데 값을 여러개 가져와야되서 baseadpater를 썻는데, 마지막 값만 커스텀 리스트 뷰에 하나만
출력이 되는데 왜 그렇게 되는지 모르겠습니다....
소스를 첨부하겠습니다.
protected void onPostExecute(String result){
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(result));
int eventType = xpp.getEventType();
boolean bSet = false;
while (eventType != XmlPullParser.END_DOCUMENT){
if(eventType == XmlPullParser.START_DOCUMENT){
;
} else if(eventType == XmlPullParser.START_TAG){
tag_name = xpp.getName();
if(tag_name.equals("age"))
bSet = true;
} else if(eventType == XmlPullParser.TEXT){
if(bSet){
// String content = xpp.getText();
// data.append(content + "\n");
bSet = false;
}
if(tag_name.equals("filename")){
Aimage = xpp.getText(); ------>파일이름을 가져오는 놈입니다. String Aimage;로 되있습니다.
//data.append(Aimage);
}
if(tag_name.equals("age")){
Aage = xpp.getText(); ------->나이를 가져오는 놈으로 String Aage; 로 되있습니다.
item.add(Aage);
}
if(tag_name.equals("happenPlace")){
Ajuso = xpp.getText(); --------> 주소를 가져오는 놈으로 String Ajuso;으로 되있습니다.
}
testAnimals = new ArrayList<TestAnimal>();
datal = new TestAnimal(Aage,Ajuso,Aimage);
testAnimals.add(datal);
animal_adapter = new Custom_CatList_Adapter(getApplicationContext(),testAnimals);
look_cat.setAdapter(animal_adapter);
animal_adapter.notifyDataSetChanged();
} else if(eventType == XmlPullParser.END_TAG){
;
}
eventType = xpp.next();
}
} catch (Exception e){
}
}
그 다음에
baseadaptaer부분입니다.
public class Custom_CatList_Adapter extends BaseAdapter{
ArrayList<TestAnimal> testAnimals;
Context context;
LayoutInflater inflater;
public Custom_CatList_Adapter(Context context, ArrayList<TestAnimal> testAnimals){
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
this.testAnimals = testAnimals;
}
public int getCount(){
return testAnimals.size();
}
public Object getItem(int position){
return testAnimals.get(position);
}
public long getItemId(int position){
return position;
}
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView;
if(v == null){
// v = inflater.inflate(R.layout.cat_custom, parent, false);
inflater = LayoutInflater.from(parent.getContext());
v = inflater.inflate(R.layout.cat_custom, parent, false);
}
//}
TestAnimal testAnimal = testAnimals.get(position);
TextView imageView = (TextView)v.findViewById(R.id.imageView);
TextView find_jang_so = (TextView)v.findViewById(R.id.find_jang_so);
TextView find_age = (TextView)v.findViewById(R.id.find_age);
imageView.setText(testAnimal.getAimage());
find_jang_so.setText(testAnimal.getAjuso());
find_age.setText(testAnimal.getAage());
// TextView imageView = (TextView)v.findViewById(R.id.imageView);
// imageView.setText(testAnimals.get(position).getAimage());
// TextView find_jang_so = (TextView)v.findViewById(R.id.find_jang_so);
// find_jang_so.setText(testAnimals.get(position).getAjuso());
// TextView find_age = (TextView)v.findViewById(R.id.find_age);
// find_age.setText(testAnimals.get(position).getAage());
notifyDataSetChanged();
return v;
}
}
class TestAnimal {
String Aimage, Aage, Ajuso;
public TestAnimal(String Aimage, String Aage, String Ajuso){
this.setAimage(Aimage);
this.setAage(Aage);
this.setAjuso(Ajuso);
}
public String getAimage(){
return Aimage;
}
public void setAimage(String aimage){
Aimage = aimage;
}
public String getAage(){
return Aage;
}
public void setAage(String age){
Aage = age;
}
public String getAjuso(){
return Ajuso;
}
public void setAjuso(String ajuso){
Ajuso = ajuso;
}
}
여기만 보고도 잘 못된게 있는건지 조언좀 해주세요. 부탁드립니다.
감사합니다.