메뉴 건너뛰기

app

[android] rss reader 구현

박영식2011.09.22 02:43조회 수 2415댓글 0

  • 1
    • 글자 크기
http://test.androday.com:7788/blog/?p=370

위 사이트에서 참고한 소스로 만들었다.

현재 tab 안에 넣기 위한 작업을 시도하고 있으나, 잘 되지 않는다.

일단, 작업 내용을 기록한다.


실행될 때, 불리는 파일(여기서는 tab3.java)을 아래와 같이 수정한다.

package com.paxmodept.demo;

//import android.app.Activity;
//import android.os.Bundle;
import java.io.InputStream;

import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;

import com.paxmodept.demo.IconTextItem;
import com.paxmodept.demo.IconTextListAdapter;
import com.paxmodept.demo.IconTextView;
import com.paxmodept.demo.R;
import com.paxmodept.demo.XmlData;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.Toast;

public class Tab3 extends ListActivity {
    /** Called when the activity is first created. */

ListView myListview;

IconTextView temp;

ArrayList<XmlData> m_xmlData = new ArrayList<XmlData>();

IconTextListAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Use an existing ListAdapter that will map an array
// of strings to TextViews

// getListView().setTextFilterEnabled(true);

// window feature for no title - must be set prior to calling
// setContentView.
requestWindowFeature(Window.FEATURE_CONTEXT_MENU);

//setContentView(R.layout.tab3);

// myListview = (ListView) findViewById(R.id.myListview);

adapter = new IconTextListAdapter(this);
// add four items
Resources res = getResources();

m_xmlData = getXmlData("vicolochurch");

// m_xmlData 가져오기

Iterator<XmlData> it = m_xmlData.iterator();

while (it.hasNext()) {
// Book str = it.next();
XmlData xmlData = it.next();
adapter.addItem(new IconTextItem(res.getDrawable(R.drawable.arrow),
xmlData.d_title, xmlData.d_link, xmlData.d_author));
}

setListAdapter(adapter);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub

IconTextItem Item = (IconTextItem) adapter.getItem(position);
String[] data = Item.getData();

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(data[1]));
startActivity(intent);
}

public ArrayList<XmlData> getXmlData(String searchTxt) {

String m_sConnectUrl = "http://gdata.youtube.com/feeds/base/users/" + searchTxt + "/uploads?orderby=updated&alt=rss&client=ytapi-youtube-rss-redirect&v=2";

XmlData xmlData = null;

String sTag;

try {

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();

URL u = new URL(m_sConnectUrl);
// InputStream in = u.openConnection().getInputStream();
InputStream in = u.openStream();
xpp.setInput(in, "utf-8");

int eventType = xpp.getEventType();

while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
// System.out.println("Start document");
} else if (eventType == XmlPullParser.END_DOCUMENT) {
// System.out.println("End document");
} else if (eventType == XmlPullParser.START_TAG) {

Log.e("START_TAG", xpp.getName());
sTag = xpp.getName();

if (sTag.equals("title")) {
// Log.e("title_getText",xpp.nextText());
xmlData = new XmlData();
xmlData.d_title = xpp.nextText();
}
if (sTag.equals("link")) {
xmlData.d_link = xpp.nextText();
}
if (sTag.equals("creator")) {
// Log.e("title_getText",xpp.nextText());
xmlData.d_author = xpp.nextText();
}

// System.out.println("Start tag "+xpp.getName());
} else if (eventType == XmlPullParser.END_TAG) {
// System.out.println("End tag "+xpp.getName());
sTag = xpp.getName();
if (sTag.equals("item")) {
m_xmlData.add(xmlData);
xmlData = null;
}
} else if (eventType == XmlPullParser.TEXT) {
// System.out.println("Text "+xpp.getText());
}
eventType = xpp.next();
}

} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(), "Connect failed",
Toast.LENGTH_SHORT);
}
return m_xmlData;
}

}


res 폴더의 layout 에 listitem.xml, styles.xml arrow.png 파일을 올바른 경로로 복사한다.
IconTextItem.java, IconTextListAdapter.java, IconTextView.java, XmlData.java 를 java 파일들이 있는 경로로 복사하면, R.java 에 여러가지 변수들이 자동 등록되면서 실행해 볼 수 있다.

target을 잘 생성해서 실행하면 된다. (여기서는 Google APIs - API Level 7로 테스트 했다.)

이 소스는 http://code.google.com/p/vicolochurch/ 에서 관리한다.

박영식 (비회원)
  • 1
    • 글자 크기

댓글 달기

suritam9
2013.04.25 조회 5851
suritam9
2013.04.04 조회 2007
suritam9
2012.09.14 조회 2368
suritam9
2012.06.24 조회 2223
suritam9
2012.06.24 조회 2564
suritam9
2012.06.24 조회 2391
suritam9
2012.06.22 조회 2437
이전 1 2 3 4 5 6 7 8 9 10... 14다음
첨부 (1)
v2.jpg
77.1KB / Download 40
위로