2011-07-27 4 views
0

저는 안드로이드 개발에 초보자입니다. 회 전자에 저장된 이름에 따라 번호를 원합니다. in1.6을 사용하여 어떻게하면 도움이되는지 알려주세요. 이 이름은 당신이 찾고있는 이름과 동일한 경우 체크 같은 시간에 커서 데이터를 통해 다음 루프의 contnent 제공자를 조회 번호를 모두 얻을 시작으로특정 번호에 대해 쿼리를 사용하는 방법은 무엇입니까?

spinner.setOnItemSelectedListener(new OnItemSelectedListener() 
    { 
    @Override 
    public void onNothingSelected(AdapterView<?> arg0) 
    { 
    } 
    @Override 
    public void onItemSelected(AdapterView<?> parent, View arg1, 
      int pos, long arg3) 
    { 
     String name,s; 
     int i; 
     name=parent.getItemAtPosition(pos).toString(); 

       //String projection1[]={People._ID,People.NAME,People.NUMBER};  
       //Cursor cur=getContentResolver().query(People.CONTENT_URI, 
       //    projection1,People.NAME+"="+name,null,null); 
       // s=cur.getString(cur.getColumnIndex(People._ID)); 
     Toast.makeText(parent.getContext(),name,Toast.LENGTH_LONG).show(); 
    } 
}); 

답변

0

진행하십시오.

cur.moveToFirst(); 
boolean found=false; 
while(cur.isAfterLast()==false || found==false) 
{ 
    if(name.equalsIgnoreCase(cur.getString(cur.getColumnIndex(People._ID))) 
    { 
     found==true; 
     // other things to do when the name is found 
    } 
cur.moveToNext(); 
} 
+0

덕분에 내가 그 커서 CUR = getContentResolver() 쿼리 (People.CONTENT_URI, projection1, People.NAME + "="+ 이름처럼 사용할 수 없습니다 니콜라 , null, null); 그 후에 사람들을 사용하십시오 .NUMBER – Arpit

관련 문제