Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7953007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:02:04+00:00 2026-06-04T03:02:04+00:00

Here is the source — I get errors when I try to add +

  • 0

Here is the source — I get errors when I try to add + ” Order by lastname”
Any ideas? (definitely a newbie)
I have // in front of my attempt about 55 lines down.
I am trying to get the results to be sorted by lastname

package com.tritech.colony;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class SearchPersonByColonyActivity extends Activity implements    OnItemClickListener
{
    private EditText searchPersonByColonyEditText ;
    private SQLiteDatabase db ;
    private Cursor cursor ;
    private ListAdapter adapter ;
    private ListView personByColonyListView ;
    private DatabaseHelper databaseHelper ;
    private String colonyName ;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.searchpersonbycolony);
        this.colonyName =     this.getIntent().getStringExtra(DatabaseHelper.KEY_COLONY_NAME);
        this.databaseHelper = new DatabaseHelper(this);
        this.databaseHelper.createDatabase();
        try {
            this.databaseHelper.openDatabase();
        } catch( SQLException ex ) {
            Log.e( DatabaseHelper.TAG, "Database can not be opened", ex);
        }
        this.databaseHelper.close();
        this.db = this.databaseHelper.getReadableDatabase() ;
        this.searchPersonByColonyEditText =         (EditText)this.findViewById(R.id.searchPersonByColonyEditText);
        this.personByColonyListView = (ListView)this.findViewById(R.id.searchPersonByColonyList);
        this.personByColonyListView.setOnItemClickListener(this);
        this.cursor = this.db.rawQuery("SELECT _id as _id , " + 
                DatabaseHelper.KEY_LAST_NAME + " , " + 
                DatabaseHelper.KEY_FIRST_NAME + " , " +
                "\"" + DatabaseHelper.KEY_SR_JR + "\" " + 
                "FROM " + DatabaseHelper.TABLE_NAME + 
                " WHERE " + DatabaseHelper.KEY_COLONY_NAME + " LIKE ?", 
                new String[] { this.colonyName } );
// tried these for line above and they fails
// new String[] { this.colonyName } + " ORDER BY " + DatabaseHelper.KEY_LAST_NAME );
// new String[] { this.colonyName } + " ORDER BY lastname" );

        this.startManagingCursor(this.cursor);
        this.adapter = new SimpleCursorAdapter(this, 
                R.layout.searchpersonbycolonyrow , 
                this.cursor , 
                new String[] { DatabaseHelper.KEY_LAST_NAME ,     DatabaseHelper.KEY_FIRST_NAME , DatabaseHelper.KEY_SR_JR }, 
                new int[] { R.id.searchPersonByColonyLastnameTextView ,         R.id.searchPersonByColonyFirstnameTextView , R.id.searchPersonByColonySrJrTextView } );
        this.personByColonyListView.setAdapter(this.adapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        boolean back_tag = this.getSharedPreferences(MainActivity.TAG, MODE_PRIVATE).getBoolean(MainActivity.BACK_TAG, false);
        if( back_tag ) {
            this.finish();
        }
    }

    public void searchPerson( View v ) {
        String text = this.searchPersonByColonyEditText.getText().toString();
        if( !text.equals("") ) {
            this.cursor = this.db.rawQuery("SELECT _id as _id , " + 
                DatabaseHelper.KEY_LAST_NAME + " , " + 
                    DatabaseHelper.KEY_FIRST_NAME + " , " +
                    "\"" + DatabaseHelper.KEY_SR_JR + "\" " + 
                    "FROM " + DatabaseHelper.TABLE_NAME + 
                    " WHERE " + DatabaseHelper.KEY_COLONY_NAME + " LIKE ?" + 
                    " AND " + DatabaseHelper.KEY_LAST_NAME + " LIKE ?" , 
                    new String[] { this.colonyName , "%"+text+"%" } );
        } else {
            this.cursor = this.db.rawQuery("SELECT _id as _id , " + DatabaseHelper.KEY_LAST_NAME + " , " + DatabaseHelper.KEY_FIRST_NAME + " FROM " +     DatabaseHelper.TABLE_NAME + " WHERE " + DatabaseHelper.KEY_COLONY_NAME + " LIKE ?", new String[] { this.colonyName } );
            this.cursor = this.db.rawQuery("SELECT _id as _id , " + 
                    DatabaseHelper.KEY_LAST_NAME + " , " + 
                    DatabaseHelper.KEY_FIRST_NAME + " , " +
                    "\"" + DatabaseHelper.KEY_SR_JR + "\" " + 
                    "FROM " + DatabaseHelper.TABLE_NAME + 
                    " WHERE " + DatabaseHelper.KEY_COLONY_NAME + " LIKE ?", 
                    new String[] { this.colonyName } );
        }
        this.startManagingCursor(this.cursor);
        this.adapter = new SimpleCursorAdapter(this, 
                R.layout.searchpersonbycolonyrow , 
                this.cursor , 
                new String[] { DatabaseHelper.KEY_LAST_NAME ,     DatabaseHelper.KEY_FIRST_NAME , DatabaseHelper.KEY_SR_JR }, 
                new int[] { R.id.searchPersonByColonyLastnameTextView ,     R.id.searchPersonByColonyFirstnameTextView , R.id.searchPersonByColonySrJrTextView } );
        this.personByColonyListView.setAdapter(this.adapter);
    }

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent( this , PersonDetailsActivity.class );
        Cursor cursor = (Cursor)this.adapter.getItem(position);
        intent.putExtra(DatabaseHelper.KEY_ID, cursor.getInt(     cursor.getColumnIndex(DatabaseHelper.KEY_ID) ) );
        this.startActivity(intent);
    }

    protected void onDestroy() {
        this.cursor.close();
        this.databaseHelper.close();
    super.onDestroy();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:02:05+00:00Added an answer on June 4, 2026 at 3:02 am

    rawQuery() looks like it takes two arguments: the sql statement, and an array of strings that will replace the ?’s in the sql statement. If that’s correct, I think what you want is:

            this.cursor = this.db.rawQuery("SELECT _id as _id , " + 
                DatabaseHelper.KEY_LAST_NAME + " , " + 
                DatabaseHelper.KEY_FIRST_NAME + " , " +
                "\"" + DatabaseHelper.KEY_SR_JR + "\" " + 
                "FROM " + DatabaseHelper.TABLE_NAME + 
                " WHERE " + DatabaseHelper.KEY_COLONY_NAME + " LIKE ? ORDER BY " 
                + DatabaseHelper.KEY_LAST_NAME, 
                new String[] { this.colonyName } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
I have an application I need to analyze. I have the source code here.
I'm trying to get eclair sources as described here: http://source.android.com/source/downloading.html but getting into trouble
I have some weird js-source here, that comapres a string to a twodimensional array:
I have downloaded the Android source code by following the steps given here http://source.android.com/source/downloading.html
I'm trying to perform a skew on an image, like one shown here (source:
Here is source code: @OneToOne(fetch = FetchType.LAZY) @Cascade({SAVE_UPDATE, EVICT, DELETE}) @JoinColumn(name = A_ID, nullable
To see what I mean, check out my source here in IE. When you
var _thumb = $('.galleria img[@rel='+_src+']'); Full source here Is it a deprecated selector?
Hey all. I've downloaded and moved the Xerces (v3.1.1) source here: /usr/include/xerces and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.