0

我正在使用SimpleCursorAdapter从数据库中填充名称列的微调器。显示数据库中选择的项目的数据库详细信息

适配器:

spinnerAdapter = new SimpleCursorAdapter(
     this, 
     android.R.layout.simple_spinner_item, 
     null, 
     new String[] {SupplierEntry.COLUMN_SUPPLIER_NAME}, 
     new int[] {android.R.id.text1}, 
     0); 
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item); 
mSuppliersSpinner.setAdapter(spinnerAdapter); 

getLoaderManager().initLoader(SUPPLIERS_LOADER, null, this); 

光标装载机:

@Override 
    public Loader<Cursor> onCreateLoader(int i, Bundle bundle) { 
     // Define a projection that specifies the columns from the table we care about. 
     String[] projection = { 
       SupplierEntry._ID, 
       SupplierEntry.COLUMN_SUPPLIER_NAME}; 

     // This loader will execute the ContentProvider's query method on a background thread 
     return new CursorLoader(this,  // Parent activity context 
       SupplierEntry.CONTENT_URI, // Provider content URI to query 
       projection,     // Columns to include in the resulting Cursor 
       null,      // No selection clause 
       null,      // No selection arguments 
       null);      // Default sort order 
    } 

我怎么可能,在离心器中选择一个项目(名称列),显示出一些textviews所有其他细节?

回答

1

首先,为微调器设置一个侦听器,以便在选择某个项目时获得回调。

mSuppliersSpinner.setOnItemSelectedListener(this); 

我提供“这个”作为听众,因为我的片段/活动实现了接口,但你可以写在括号中的一个为好。 可以实现此方法:

@Override 
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) 
{ 
    //Start another cursorloader to get the details 
} 

基于ID,或位置,你知道选择哪个条目。此时您可以启动另一个CursorLoader(带有选择,因此您只能获得此特定条目的详细信息)。当您在onLoadFinished中获得回调时,可以在TextView中显示详细信息。

相关问题