Ya, exactly please see the code I need to fetch something in the adapter
area but do not understand how to do it, please help.
*
package* com.example.HelloSpinner;
*
import* android.app.Activity;
*
import* android.content.ContentUris;
*
import* android.content.Intent;
*
import* android.database.Cursor;
*
import* android.os.Bundle;
*
import* android.provider.Contacts.People;
*
import* android.provider.Contacts.Phones;
*
import* android.view.View;
*
import* android.widget.AdapterView;
*
import* android.widget.SimpleCursorAdapter;
*
import* android.widget.Spinner;
*
import* android.widget.Toast;
*
import* android.widget.AdapterView.OnItemSelectedListener;
*
public* *class* HelloSpinner *extends* Activity
{
*public* *void* onCreate(Bundle savedInstanceState)
{
*super*.onCreate(savedInstanceState);
setContentView(R.layout.*main*);
String[] *PROJECTION* = *new* String[]
{
People.*_ID*, People.*NAME
*
};
Spinner spinner = (Spinner) findViewById(R.id.*spinner*);
spinner.setOnItemSelectedListener(*new* MyOnItemSelectedListener());
Cursor cur = getContentResolver().query(People.*CONTENT_URI*, *null*, *null*,
*null*, *null*);
SimpleCursorAdapter adapter2 = *new* SimpleCursorAdapter(*this*,
android.R.layout.*simple_spinner_item*,
// Use a template
// that displays a
// text view
cur,
// Give the cursor to the list adapter
*new* String[] {People.*NAME*},
// Map the NAME column in the
// people database to...
*new* *int*[] {android.R.id.*text1*});
// The "text1" view defined in
// the XML template
adapter2.setDropDownViewResource(android.R.layout.*
simple_spinner_dropdown_item*);
spinner.setAdapter(adapter2);
} // The create method ends
*public* *class* MyOnItemSelectedListener *implements*OnItemSelectedListener
{
*public* *void* onItemSelected(AdapterView<?> parent,
View view, *int* pos, *long* id)
{
Intent intent = *new* Intent(Intent.*ACTION_CALL*);
Cursor cursor = *(Cursor) AdapterView.*;
*long* phoneId = cursor.getLong(cursor.getColumnIndex(People.*
PRIMARY_PHONE_ID*));
intent.setData(ContentUris.*withAppendedId*(Phones.*CONTENT_URI*, phoneId));
startActivity(intent);
Toast.*makeText*(parent.getContext(),
"The Person is " +
parent.getItemAtPosition(pos).toString(),
Toast.*LENGTH_LONG*).show();
}
*public* *void* onNothingSelected(AdapterView<?> parent)
{
// Do nothing.
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
To unsubscribe, reply using "remove me" as the subject.