import java.util.ArrayList;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class CLMperson_pushselection extends ListActivity {
 String tag = "push_selection";
 
 ArrayList<PersonPush> m_pList;
 int ppos;
 
 class PersonPush 
 {
  private String name;
  private String phone_num;
  public int time;
  
  public PersonPush(String _name, String _number){
   this.name = _name;
   this.phone_num = _number;
   this.time = 0;
  }
  
  public String getName(){
   return name;
  }
  public String getNumber(){
   return phone_num;
  }
 }
 
 private class pushSelectAdapter extends ArrayAdapter<PersonPush> {
  private ArrayList<PersonPush> items;
  private int pos;
  private Activity context;
  public  ArrayAdapter<CharSequence> adPushSpin;
  
  public pushSelectAdapter( Context context, int textViewResourceId, ArrayList<PersonPush> items){
   super(context, textViewResourceId, items);
   this.items = items;
   this.context = getParent();
  }

  private PersonPush getModel(int position)
  {
   return(((pushSelectAdapter)getListAdapter()).getItem(position));
  }
  
  @Override
  public View getView(int position, View converView, ViewGroup parent){
   View v = converView;
   ViewWrapper wrapper;
   TextView pushName;
   Spinner pushSpin;
   pos = position;
   
   if( v == null){
    LayoutInflater inflater = context.getLayoutInflater();
    v = inflater.inflate(R.layout.pushselection, null);
    wrapper=new ViewWrapper(v); 
    v.setTag(wrapper);
   }
   else {
    wrapper=(ViewWrapper)v.getTag();
   }
   
   // ViewWrapper 에 있는 Spinner 과 Textview 를 연결
   pushSpin = wrapper.getSpinner();
   pushName = wrapper.getName();
   
   
   // Spinner에 있는 알림을 선택하였을 경우 
   pushSpin.setOnItemSelectedListener(new OnItemSelectedListener()
         {    
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id){
           //String[] methods = getResources().getStringArray(R.array.pushtime);
           //String a = parent.getItemAtPosition(position).toString();
           if( position != 0)
           { // 1달 3달 6달 이 String 이므로 int형으로 바꾸어 주기 위해 순서에 따라 자동으로 선택되게 하였다.
            items.get(pos).time = (position+1)/2*position;
           }
           
          }
        
          // 현재 필요는 없지만, 반드시 재정의해야하는 함수, 내용은 없음
          public void onNothingSelected(AdapterView<?> arg0){}
   });
           
   // spinner 안의 내용 표시에 대한 설정
   pushSpin.setPrompt("알림 시간을 선택하세요");
   pushSpin.setFocusable(false);
   
   adPushSpin = ArrayAdapter.createFromResource(context, R.array.pushtime, android.R.layout.simple_spinner_item);
   adPushSpin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   pushSpin.setAdapter(adPushSpin);
   
   // 연락처에 기록된 이름 출력
   PersonPush m_pp = items.get(position);
   if( m_pp != null && pushName != null){
     pushName.setText(m_pp.getName());
   }
   
   return v;
  }
 }
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.listview);
  ppos = 0;
  
  m_pList = new ArrayList<CLMperson_pushselection.PersonPush>();
 
  Cursor cursor = getURI();
  
  int end = cursor.getCount();    // 전화번호부의 갯수 세기
  Log.d(tag, "end = "+end);
  String [] name = new String[end]; // 전화번호부의 이름을 저장할 배열 선언
  int count = 0; 
  if(cursor.moveToFirst()) 
  {
   // 컬럼명으로 컬럼 인덱스 찾기 
   int idIndex = cursor.getColumnIndex("_id");
   do 
   {
    // 요소값 얻기
    int id = cursor.getInt(idIndex);   
    name[count] = cursor.getString(1);
    // LogCat에 로그 남기기
    Log.d(tag, "id=" + id +", name["+count+"]=" + name[count]);    
    
    PersonPush p = new PersonPush(name[count], cursor.getString(2));
    m_pList.add(p);
    
    count++;
    
   } while(cursor.moveToNext() || count > end);
  }
  
  pushSelectAdapter m_adapter = new pushSelectAdapter(this, R.layout.pushselection, m_pList);
  setListAdapter(m_adapter);  
  
  
 }
 
 private Cursor getURI() 
 {
  // 주소록 URI  
  Uri people = Phone.CONTENT_URI;
  
  // 검색할 컬럼 정하기
  String[] projection = new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER };
  
  // 쿼리 날려서 커서 얻기
  String[] selectionArgs = null;
  String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; 
  return managedQuery(people, projection, null, selectionArgs, sortOrder);
 }

 @Override
 public void onListItemClick(ListView parant, View v, int position, long id)
 {
  ppos = position;
  
 }
 
 public void onBackPressed() {
  
  CLManagerTab.ManagerTab.back();
 }
}




1. 죄송하지만 다시 한번 질문 드립니다.

 


현재 그림처럼 ListView에 spinner를 넣었습니다.

위에는 소스를 첨부하였습니다.

제가 궁금한 점은 Spinner의 값을 변경했을 경우 해당 라인의 textview의 값을 얻어오고 싶습니다.
결정적으로 listview안의 해당 text의 position값을 못 구하겠더군요... 그 위치값만 어떻게 얻어오는 방법 좀 알고싶습니다. 부탁드려요.


해결을 해서 혹시나 참고하실 분이 계실까 생각해서 소스 다시 붙입니다.(해결 후 소스)

public class CLMperson_pushselection extends ListActivity {

 String tag = "push_selection";
 
 ArrayList<PersonPush> m_pList;
 int ppos;
 
 class PersonPush 
 {
  private String name;
  private String phone_num;
  public int selectTimeId = 0;
  public int time;
  
  public PersonPush(String _name, String _number){
   this.name = _name;
   this.phone_num = _number;
   this.time = 0;
  }
  
  public String getName(){
   return name;
  }
  public String getNumber(){
   return phone_num;
  }
 }

    // 제공되는 position에 따른 ListArray 요소를 리턴
    private PersonPush getModel(int position) {
        return (((pushSelectAdapter)getListAdapter()).getItem(position));
    }  
 
 
 private class pushSelectAdapter extends ArrayAdapter<PersonPush> {
  private int pos;
  private Activity context;
  public  ArrayAdapter<CharSequence> adPushSpin;
  
  public pushSelectAdapter( Context context, int textViewResourceId, ArrayList<PersonPush> items){
   super(context, textViewResourceId, items);
   this.context = getParent();
  }

 private PersonPush getModel(int position)
  {
   return(((pushSelectAdapter)getListAdapter()).getItem(position));
  }
  
  @Override
  public View getView(int position, View converView, ViewGroup parent){
   View v = converView;
   ViewWrapper wrapper;
   TextView pushName;
   Spinner pushSpin;
   
   // getView를 처음 호출하는가 아닌가? (재사용성 때문)
   if( v == null){
    LayoutInflater inflater = context.getLayoutInflater();
    v = inflater.inflate(R.layout.pushselection, null);
    wrapper= new ViewWrapper(v); 
    v.setTag(wrapper);
    
    // ViewWrapper 에 있는 Spinner 과 Textview 를 연결
    pushName = wrapper.getName();
    pushSpin = wrapper.getSpinner();
    
    // Spinner에 있는 알림을 선택하였을 경우 
    pushSpin.setOnItemSelectedListener(new OnItemSelectedListener()
          {    
           public void onItemSelected(AdapterView<?> parent, View view, int position, long id){
                       
            if( position != 0)
            {
             
             Integer pos2 = (Integer)parent.getTag(); // setTag 해서 position 값을 얻어온 부분
             PersonPush model = getModel(pos2);
             
             model.time = (position+1)/2*position;
             model.selectTimeId = position;
            }
            
           }
         
           // 현재 필요는 없지만, 반드시 재정의해야하는 함수, 내용은 없음
           public void onNothingSelected(AdapterView<?> arg0){}
    });
    
    
   }
   else {
    wrapper=(ViewWrapper)v.getTag();
    
    // ViewWrapper 에 있는 Spinner 과 Textview 를 연결
    pushName = wrapper.getName();
    pushSpin = wrapper.getSpinner();
   }
           
   
   PersonPush model = getModel(position);
   
   // spinner 안의 내용 표시에 대한 설정
   pushSpin.setPrompt("알림 시간을 선택하세요");
   
   // 현재 convertView 내부의 Spinner에 Integer형 position tag 달기
            // Spinner의 callback에서 사용 함.
   pushSpin.setTag(new Integer(position)); 
   
  
   adPushSpin = ArrayAdapter.createFromResource(context, R.array.pushtime, android.R.layout.simple_spinner_item);
   adPushSpin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   pushSpin.setAdapter(adPushSpin);

   // spinner의 변경된 값을 유지시켜줌
   pushSpin.setSelection(model.selectTimeId);
   
   // 연락처에 기록된 이름 출력
   if( model != null && pushName != null)
   {
    pushName.setText(model.getName());
   }
   
   return v;
  }
 }
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.listview);
  ppos = 0;
  
  m_pList = new ArrayList<CLMperson_pushselection.PersonPush>();
 
  Cursor cursor = getURI();
  
  int end = cursor.getCount();    // 전화번호부의 갯수 세기
  Log.d(tag, "end = "+end);

  String [] name = new String[end]; // 전화번호부의 이름을 저장할 배열 선언
  int count = 0; 

  if(cursor.moveToFirst()) 
  {
   // 컬럼명으로 컬럼 인덱스 찾기 
   int idIndex = cursor.getColumnIndex("_id");

   do 
   {
    // 요소값 얻기
    int id = cursor.getInt(idIndex);   
    name[count] = cursor.getString(1);
    // LogCat에 로그 남기기
    Log.d(tag, "id=" + id +", name["+count+"]=" + name[count]);    
    
    PersonPush p = new PersonPush(name[count], cursor.getString(2));
    m_pList.add(p);
    
    count++;
    
   } while(cursor.moveToNext() || count > end);
  }
  
  pushSelectAdapter m_adapter = new pushSelectAdapter(this, R.layout.pushselection, m_pList);
  setListAdapter(m_adapter);  
  
  
 }
 
 private Cursor getURI() 
 {
  // 주소록 URI  
  Uri people = Phone.CONTENT_URI;
  
  // 검색할 컬럼 정하기
  String[] projection = new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER };
  
  // 쿼리 날려서 커서 얻기
  String[] selectionArgs = null;
  String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; 
  return managedQuery(people, projection, null, selectionArgs, sortOrder);
 }

 public void onBackPressed() {  
  CLManagerTab.ManagerTab.back();
 }
}