Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 显示微调器中所选项目的数据库详细信息_Android_Sqlite_Android Sqlite_Simplecursoradapter_Android Cursorloader - Fatal编程技术网

Android 显示微调器中所选项目的数据库详细信息

Android 显示微调器中所选项目的数据库详细信息,android,sqlite,android-sqlite,simplecursoradapter,android-cursorloader,Android,Sqlite,Android Sqlite,Simplecursoradapter,Android Cursorloader,我正在使用SimpleCursorAdapter从数据库中使用name列填充微调器 适配器: spinnerAdapter = new SimpleCursorAdapter( this, android.R.layout.simple_spinner_item, null, new String[] {SupplierEntry.COLUMN_SUPPLIER_NAME}, new int[] {android.R

我正在使用SimpleCursorAdapter从数据库中使用name列填充微调器

适配器:

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
    }
@覆盖
公共加载器onCreateLoader(inti,Bundle){
//定义一个投影,指定我们关心的表中的列。
字符串[]投影={
供应商条目。\u ID,
SupplierEntry.COLUMN\u SUPPLIER\u NAME};
//此加载程序将在后台线程上执行ContentProvider的查询方法
返回新的游标装入器(此,//父活动上下文
SupplierEntry.CONTENT\u URI,//要查询的提供程序内容URI
投影,//要包含在结果游标中的列
null,//无选择子句
null,//没有选择参数
null);//默认排序顺序
}

在微调器(名称列)中选择一个项目后,如何在某些文本视图中显示所有其他详细信息?

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

mSuppliersSpinner.setOnItemSelectedListener(this);
我提供“this”作为侦听器,因为我的片段/活动实现了接口,但您也可以在括号之间编写一个。 您可以实现此方法:

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
    //Start another cursorloader to get the details
}
@覆盖
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id)
{
//启动另一个游标加载程序以获取详细信息
}
根据id或位置,您知道选择了哪个条目。此时,您可以启动另一个游标加载程序(使用一个选择,以便只获取此特定条目的详细信息)。当您在onLoadFinished中收到回调时,您可以在文本视图中显示详细信息