<?xml version="1.0" ?>
위 내용을 파싱하는 중인데요.
while(parser.getEventType() != XmlPullParser.END_DOCUMENT) {
switch(parser.getEventType()) {
case XmlPullParser.START_DOCUMENT: // 문서의 시작
break;
case XmlPullParser.END_DOCUMENT: // 문서의 끝
break;
case XmlPullParser.START_TAG:
Log.d("", "Start_tag 시작");
kind=parser.getName();
System.out.println("Tag = " + kind);
if(parser.getName().equals("current_conditions")){
d_weather = new WeatherData();
}
if(parser.getName().equals("condition")){
state = parser.getAttributeValue(0);
d_weather.setState(state);
}
if(parser.getName().equals("temp_c")){
temp = parser.getAttributeValue(0);
d_weather.setState(temp);
}
if(parser.getName().equals("wind_condition")){
wind = parser.getAttributeValue(0);
d_weather.setState(wind);
}
if(parser.getName().equals("forecast_conditions")){
break;
}
break;
case XmlPullParser.END_TAG:
break;
case XmlPullParser.TEXT:
break;
}
parser.next();
}
m_adapter.add(d_weather);
<list선언>
ArrayList<WeatherData> m_weather = new ArrayList<WeatherData>(); WeatherData d_weather; WeatherAdapter m_adapter;
<weatheradapter>
private class WeatherAdapter extends ArrayAdapter<WeatherData> {
private ArrayList<WeatherData> items;
public WeatherAdapter(Context backThread, int textViewResourceId, ArrayList<WeatherData> items) {
super(backThread, textViewResourceId, items);
this.items = items;
}
public int size() {
// TODO Auto-generated method stub
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.weather_row, null);
}
WeatherData w = items.get(position);
TextView w_state = (TextView) v.findViewById(R.id.state);
TextView w_tmn = (TextView) v.findViewById(R.id.tmn);
TextView w_tmx = (TextView) v.findViewById(R.id.tmx);
if(w != null) {
if(w_state != null) {
w_state.setText(w.getState());
}
if(w_tmn != null) {
w_tmn.setText(w.getTmn());
}
if(w_tmx != null) {
w_tmx.setText(w.getTmx());
}
}
return v;
}
}
<weatherdata class>
class WeatherData {
private String State;
private String Tmn;
private String Tmx;
public void setState(String _State) {
this.State = _State;
}
public void setTmn(String _Tmn) {
this.Tmn = _Tmn;
}
public void setTmx(String _Tmx) {
this.Tmx = _Tmx;
}
public String getState() {
return State;
}
public String getTmn() {
return Tmn;
}
public String getTmx() {
return Tmx;
}
}소스는 이렇게 되어 있습니다.
m_adapter.add(d_weather)를 while문 밖으로 뺐더니
맨 마지막 데이터 한개만 들어가네요;;
START_TAG: 안에 넣으면 계속 반복되고 ㅠㅠ
리스트뷰 안에 날씨, 온도, 바람 세가지만 넣으려고 하는데
어떻게 추가를 시켜야 될까요 ㅠㅠ
어렵네요 ㅠㅠ
case XmlPullParser.START_TAG: // 시작 태그를 만나면 이름을 살펴봐서 작업(아무 일도 안하거나 값을 읽어 저장
kind=parser.getName();
System.out.println("Tag = " + kind);
if(parser.getName().equals("current_conditions")){
bcurrent_condition = true;
}
if(bcurrent_condition == true)
{
if(parser.getName().equals("condition")){
state = parser.getAttributeValue(0);
d_weather.State = state;
}
else if(parser.getName().equals("temp_c")){
temp = parser.getAttributeValue(0);
d_weather.Tmn = temp;
}
else if(parser.getName().equals("icon")){
image = "http://www.google.com" + parser.getAttributeValue(0);
d_weather.Image = image;
}
else if(parser.getName().equals("wind_condition")){
wind = parser.getAttributeValue(0);
d_weather.Tmx = wind;
}
}
break;
case XmlPullParser.END_TAG:
if(parser.getName().equals("current_conditions")){
bcurrent_condition = false;
if(d_weather != null) {
m_weather.add(d_weather);
d_weather = null;
}
}
break;
이렇게 해결했습니다




복사가 안되서 대충 수도코드 비슷하게 써드립니다.
boolean cur
case:
START_TAG
if(current_conditions)
cur=true
if(condition&&cur)
con = getAttr
if(temp&&cur)
tem = getAttr
if(wind&&cur)
win = getAttr
END_TAG
if(current_conditions)
cur=false
아까 분명히 알려드린 거 같은데.