1

検索候補にコンテンツ プロバイダーを使用していますが、候補クリックの処理に問題があります。検索はうまく機能すると説明しますが、提案をクリックすると検索アクティビティに移動しますが、何もありません。検索用の私のコード:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_list_item_2);
    DataBaseUtil.startDataBase(getApplicationContext());

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);

        Cursor cursorAdapter = GetListResult(query);

        if (cursorAdapter != null) {
            cursorAdapter.moveToFirst();
        }
        startManagingCursor(cursorAdapter);
        String[] from = new String[] { SearchManager.SUGGEST_COLUMN_ICON_1,
                BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
                "project_id" };
        int[] displayViews = new int[] { R.id.row_image, R.id.name_entry,
                R.id.name_id, R.id.name_descrption };

        final SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(
                this, R.layout.layout_row, cursorAdapter, from,
                displayViews);

        final ListView list = (ListView) findViewById(android.R.id.list);
        list.setAdapter(listAdapter);

        list.setOnItemClickListener(new ListView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> l, View v, int position,
                    long id) {
                Cursor cursor = (Cursor) listAdapter.getItem(position);
                String i = String.valueOf(cursor.getInt(cursor
                        .getColumnIndex("project_id")));

                Intent intent = new Intent(ItemIntent.this,
                        AcceuilProjet.class);
                intent.putExtra("folderId", "0");

                intent.putExtra("projectName", " ");
                intent.putExtra("projectId", Long.valueOf(i));

                startActivity(intent);
            }
        });
    }

}

これが私のプロバイダーです

@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {

    String[] columns = new String[] {
              BaseColumns._ID,
          ProjectPersistence.KEY_WORD,
          ProjectPersistence.KEY_DEFINITION,
           /* SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
                            (only if you want to refresh shortcuts) */
              SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID};

    Cursor rtnCursor = null;
    Cursor rtnCursorProject = null;

//  Cursor rtnCursorMessage = null;
    String word = uri.getLastPathSegment();

    Log.d(TAG, " Search Provider query, word: " + word);

    if (!word.equals(SEARCH_QUERY)) {
        try {
            rtnCursorProject = ProjectPersistence.fetchProjectCursor(word);

        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }


        rtnCursor = getMatrixCursor(rtnCursorProject);


    } else if (word.equals(SEARCH_QUERY_VIEW)) {
        // Handle a suggestions click (because the suggestions all use
        // ACTION_VIEW)
        try {
            rtnCursorProject = ProjectPersistence.fetchProjectCursor(word);
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Toast.makeText(getContext(), "anything", Toast.LENGTH_SHORT).show();
        Log.d("Provider", "this is a item click");
    }

    return rtnCursor;
}

できれば助けてください

4

1 に答える 1