반응형
|
안드로이드(Android) RSS 구현5 - RSS 제목별 상세내용 구현 |
|
환경 : Eclipse Mars, Android 4.2.2 |
이번에는 RSS 구현 5번째 이야기로 리스트에 제목을 클릭하게 되면 상세내용에 대해 보여주는 기능입니다. 기존에 리스트를 만든 것은 동일하며 상세페이지 구현을 위해 Activity 를 하나 추가 하였습니다.
▼ 메인 activity 에서 상세페이지로 데이터를 보내기 위해 ListActivity 의 onListItemClick() 함수를 오버라이드 합니다. 리스트에서 행을 클릭할 때 이벤트를 잡아내기 위함입니다.
▼ 위에서 만든 onListItemClick() 함수 내부를 채워넣는데 RssFeed 객체에 담긴 제목, 내용, URL, 발행날짜를 상세페이지에 표현하기 위해 넘깁니다. 넘길 때 새로 만든 상세 페이지 클래스 RssDetailActivity 로 Intent 를 사용해 전송합니다.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = new Intent(this, RssDetailActivity.class);
Bundle bundle = new Bundle();
bundle.putString("title", mRssFeed.getItem(position).getTitle());
bundle.putString("desc", mRssFeed.getItem(position).getDescription());
bundle.putString("urlLink", mRssFeed.getItem(position).getLink());
bundle.putString("pubdate", mRssFeed.getItem(position).getPubdate());
intent.putExtras(bundle);
startActivity(intent);
super.onListItemClick(l, v, position, id);
}
▼ 다음은 메인 activity 에서 보낸 데이터를 표현하기 위한 상세페이지 RssDetailActivity 의 전체 내용입니다. onCreate() 함수에서 전송받은 데이터를 받아 화면에 각 위젯에 값을 셋팅합니다.
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class RssDetailActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rss_detail);
TextView detailsTitle = (TextView) findViewById(R.id.detailstitle);
TextView detailsDescription = (TextView) findViewById(R.id.detailsdescription);
TextView detailsPubdate = (TextView) findViewById(R.id.detailspubdate);
TextView detailsLink = (TextView) findViewById(R.id.detailslink);
Bundle bundle = this.getIntent().getExtras();
detailsTitle.setText(bundle.getString("title"));
detailsDescription.setText(bundle.getString("desc"));
detailsPubdate.setText(bundle.getString("pubdate"));
detailsLink.setText(bundle.getString("urlLink"));
}
}
▼ 상세페이지 레이아웃 xml 의 전체 내용입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="RSS 상세페이지 구현 : " />
<TextView
android:id="@+id/detailstitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/detailsdescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/detailslink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web" />
<TextView
android:id="@+id/detailspubdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
▼ 이것으로 RSS 구현을 위한 시리즈는 마쳤습니다. 상세페이지까지 구현하였으며 description 부분이 조금 미흡하긴 한데 좀더 수정해서 이지미와 내용을 다시 표현해 보도록 하겠습니다.
반응형
'안드로이드 개발' 카테고리의 다른 글
| 안드로이드(Android) onDraw() 를 이용해 스크린터치로 원그리기 (1) | 2014.11.29 |
|---|---|
| 안드로이드(Android) 경고 - Custom view… overrides onTouchEvent but not performClick (0) | 2014.11.28 |
| 안드로이드(Android) onDraw 함수를 이용해 화면에 비트맵이미지, 도형 그리기 (0) | 2014.11.27 |
| 안드로이드(Android) 코드경고 – Avoid object allocations during draw/layout operations (preallocate and reuse instead) 해제 하기 (0) | 2014.11.26 |
| 안드로이드(Android) RSS 구현4 - RSS 피드 구현 제목,타이틀등 상세 구현 (0) | 2014.11.24 |
| 안드로이드(Android)RSS 구현3 - RSS 피드 읽어서 ListView 로 제목 표현하기 (0) | 2014.11.23 |
| 안드로이드(Android) RSS 구현2 - XML 파싱클래스를 이용해서 RSS Reader 구현하기 (5) | 2014.11.22 |
| 안드로이드(Android) RSS 구현1 - XmlResourceParser 를 이용하여 XML 파싱하기 (0) | 2014.11.21 |

