오픈 소스를 수정 하고 있는 중입니다.
vod를 구현 해보고 싶어서 만들고 있는데요
<one>
<item>
<title>타이틀</title>
<name>이름</name>
<datetime>2013-04-18</datetime>
<bible>성경</bible>
<movie>rtsp://localhost/1.mp4</movie>
<thumbnail>http://localhost/1.jpg</thumbnail>
</item>
</one>
위에껄 파싱을 하는데요
썸네일 까지 파싱을 해서 결과치는 정상으로 나옵니다.
그런데 movie 데이터를 어디서 가져와야될지 모르겠습니다.
main.java
AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
// TODO Auto-generated method stub
AlertDialog.Builder dialog = new AlertDialog.Builder(vod.this);
dialog.setTitle("알려드립니다");
dialog.setMessage("3G, 4G 사용 시 데이터 이용료가 부과될 수 있습니다");
dialog.setPositiveButton("확인", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
String path = rtsp주소
Intent i;
try {
i = Intent.parseUri(path, Intent.URI_INTENT_SCHEME);
startActivity(i);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
dialog.setNegativeButton("취소", null);
dialog.show();
}
};
forecast.java
public class Forecast {
public String title;
public String datetime;
public String bible;
public String thumbnail;
public String name;
public String movie;
}
parser.java
public class Parser {
private String TAG = "Parser";
ArrayList<Forecast> parse;
Parser() {
parse = new ArrayList<Forecast>();
}
ArrayList<Forecast> parse() {
try {
String url = "http://localhost/search.php";
URL targetURL = new URL(url);
InputStream is = targetURL.openStream();
//Parser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(is, "utf-8");
String tag;
Forecast f = null;
int parserEvent = parser.getEventType();
while(parserEvent != XmlPullParser.END_DOCUMENT) {
Log.d(TAG, "hi");
switch(parserEvent) {
case XmlPullParser.END_TAG:
tag = parser.getName();
Log.d(TAG, "END_TAG");
if(tag.compareTo("item") == 0) {
parse.add(f);
Log.d(TAG, "/item");
}
break;
case XmlPullParser.START_TAG:
tag = parser.getName();
Log.d(TAG, "START_TAG : " + tag);
if(tag.compareTo("item") == 0) {
f = new Forecast();
} else if(f != null && tag.compareTo("title") == 0) {
f.title = parser.nextText();
Log.d(TAG, f.title);
} else if(f != null && tag.compareTo("datetime") == 0) {
f.datetime = parser.nextText();
} else if(f != null && tag.compareTo("bible") == 0) {
f.bible = parser.nextText();
} else if(f != null && tag.compareTo("thumbnail") == 0) {
f.thumbnail = parser.nextText();
} else if(f != null && tag.compareTo("name") == 0) {
f.name = parser.nextText();
} else if(f != null && tag.compareTo("movie") == 0) {
f.movie = parser.nextText();
}
break;
}
parserEvent = parser.next();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return parse;
}
}
adapter.java
public class Adapter extends ArrayAdapter<Forecast> {
private View v;
private ViewHolder holder;
// private Handler mHandler;
public Adapter(Context context, int resource,
List<Forecast> objects) {
super(context, resource, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
v = inflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.title = (TextView) v.findViewById(R.id.title);
holder.datetime = (TextView) v.findViewById(R.id.datetime);
holder.bible = (TextView) v.findViewById(R.id.bible);
holder.name = (TextView) v.findViewById(R.id.name);
holder.thumbnail = (ImageView) v.findViewById(R.id.thumbnail);
v.setTag(holder);
} else {
v = convertView;
holder = (ViewHolder) v.getTag();
}
final Forecast f = getItem(position);
holder.title.setText(f.title);
holder.datetime.setText(f.datetime);
holder.bible.setText(f.bible);
holder.name.setText(f.name);
new ImageAsync(holder.thumbnail).execute(f.thumbnail);
return v;
}
}
class ImageAsync extends AsyncTask<String, String, ImageView> {
Bitmap bm;
ImageView mImg;
ImageAsync(ImageView img) {
mImg = img;
}
@Override
protected ImageView doInBackground(String... params) {
try {
URL url = new URL(params[0]);
Log.d("TA", params[0]);
URLConnection connection = url.openConnection();
connection.connect();
InputStream is = connection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
// TODO: handle exception
}
return null;
}
@Override
protected void onPostExecute(ImageView imgView) {
mImg.setImageBitmap(bm);
}
}
class ViewHolder {
TextView title;
TextView datetime;
TextView bible;
TextView name;
ImageView thumbnail;
}
ㅎㅎ 소스 다 오픈 한거 같네요 저도
데이터 뽑아오는걸 공부를 하고 있는 상태에서 막상 뽑아보려니까
해깔리고 어렵고 잘 안되네요
프로그램의 흐름이 아직 이해가 잘 안되는거 같습니다.
parser.java에서 찾아봐야되나요??
혹시 여기서 리스트뷰 더보기 추가하려면 어떤식으로 해야되나요???