마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

arraylist intent할때!

0 추천
arraylist에 담긴 내용을

사용자가  onItemClick시에 position을 알아내서

그에 해당하는 arraylist의 내용을 넘기고 싶어요

 

예를 들면 리스트아이템중 3번째를 클릭했을때

age라는 arraylist의 3번째 내용만을 intent를 사용해서 다른 액티비티로 넘기고싶습니다.

계속 검색해봤는데 어떻게 해야할지 잘 모르겠네요

 

 

arraylist를 사용하지 않을때는

if (position == 0) {
       Intent intent0 = new Intent(a.this, b.class);
    intent0.putExtra("name", 10012);
    intent0.putExtra("age", 23);
    intent0.putExtra("height", 162);
       startActivity(intent0);
  }
  else if (position == 1) {
   Intent intent1 = new Intent(a.this, b.class);
   intent1.putExtra("name", 10013);
   intent1.putExtra("age", 24);
   intent1.putExtra("height", 152);
   startActivity(intent1);
  }

이런식으로 해서 넘겨줬는데 이렇게 말고 arraylist의 position을 이용해서

짜보고싶네요
익명사용자 님이 2013년 10월 5일 질문
2013년 10월 5일 수정

1개의 답변

0 추천
ArrayList<String> myList = new ArrayList<String>();

과 같이 변수 선언이 되어있다면

 

클릭시

 

String value = myList.get(position).getValue() 형태로 값을 가져올 수 있습니다.

해당 value를 intent에 담아 넘기면 되겠죠
밥아저씨 (200 포인트) 님이 2013년 10월 6일 답변
...