Android Tutorial – List View And Detail Application in Android Studio – Part 6
Hello, I’m Andy. We will continue the last tutorial.
We complete the list view and need to start develop the detail page now.
First, please create an Activity named “DetailActivity” and Android Studio will also create a layout named “activity_detail” for you.
Then, we modify the text view in the layout; create a new string for it – “Welcome to detail.“
[Image 1]
Next we go to MainActivity. Add below code at the end of onCreate method.
// Set OnItemClickListener
listView.
An error should be appear because of below reason:
[Image 2]
It is very easy to fix it, just let your activity implement that interface is OK. (This time the interface is OnItemClickListener.)
Let me show that for you
// Let Activity implement Interface
public class MainActivity extends ActionBarActivity implements AdapterView.
// Handle the OnItemClickListener itself
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Go to Detail Activity
Intent i = new Intent(MainActivity.this, DetailActivity.class);
// Send the position number to Detail Activity too.
i.putExtra(“position”, position);
// Run the process
startActivity(i);
}
Run the application. Now you can go to the DetailActivity by click each item in listView and back to the MainActivity by click the back button in simulator.
[Image 3]
[Image 4]
'Android' 카테고리의 다른 글
안드로이드 스튜디오 Daum map 라이브러리 사용방법 (0) | 2015.12.29 |
---|---|
<Android> GPS 위도,경도,주소 불러오기 (0) | 2015.12.28 |
Fragment animation 효과 (0) | 2015.12.24 |
Fragment를 이용하여 안드로이드 화면구성하기 (0) | 2015.12.23 |
Viewpager (0) | 2015.12.22 |