2011-07-27 13 views
0

私はアンドロイド開発には初めてです。私はスピナーに格納されている名前に応じて番号を欲しいです。特定の番号のクエリを使用するには?

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

あなたはcontnentプロバイダに問い合わせを始めとして名前が、あなたが探している名前と等しい場合は、同じ時間でのカーソルのデータをループチェック、その後、すべての数字を取得し、進みます。

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

感謝のニコラ、null、null);その後、人々を使用します.NUMBER – Arpit

関連する問題