Tuesday, May 17, 2011

Showing an Android Activity as a Dialog

After looking through the Google API documents for way to long (do they put wrong stuff in there on purpose?) I saw all the ways I didn't want to accomplish what I wanted. There is so much in the documentation!

What I wanted to do was create a screen that would open like a Dialog when something was clicked. Then the buttons would trigger an action for the item selected in the list. I knew I wanted to have this in a separate activity, but I wanted to have it display on top of the previous screen, like a dialog box.


android:theme="@android:style/Theme.Dialog"


I happened upon this answer, just put this in line into your Manifest file and the activity will have the style of a dialog! I think it makes the flow of the application much better when you have something that could have multiple actions you want to take, and you don't want to have to write excess code to accomplish. Applying different styles to individual activities in the manifest file has really improved the quality of my Android code.

Friday, April 1, 2011

Updating a Sqlite record with Android

I was having a problem updating a record using the database built into android. I had a working SQL statement, but it wasn't working using the raw sql command! I'm not sure why it wasn't working, but after reading about ContentValues I decided I wanted to use that instead. I thought it was best practice this way, but I ran into some unknown errors that the debugger was not providing much information for.

This is how I have it working for my setup:


public int updateLength(String route_length, int route_id){
ContentValues cv = new ContentValues();
cv.put("length", route_length);
return db.update(TABLE_NAME_ROUTE, cv, "id=" + route_id, null );
}


I believe there is a better way to attach the "id=" statement in the third argument of the update but I couldn't get any of these ways to work for me.

Tuesday, March 22, 2011

Android Programming Help

This is some good basic info I found really helpful. Here a cursor is opened to the database and data is fetched into an ArrayList

Also note that it is better to define what type of data will be in an ArrayList like:
ArrayList myResults = new ArrayList();



ArrayList myResults = new ArrayList();
Cursor c = db.query(...your Query Parameters here...);
c.moveToFirst();
while(!c.isAfterLast())
{
myResults.add(c.getString(1));
c.moveToNext();
}

Monday, February 14, 2011

Using CodeIgniter and Apache Rewrite for Pretty URLs

After spending two hours trying different configurations I finally found the one that worked for me. I found no shortage of help online but none helped. This is what finally worked for me.

Changed my CodeIgniter config, application/config/config.php

From this: $config['index_page'] = 'index.php';
To this: $config['index_page'] = '';

From this: $config['uri_protocol'] = 'AUTO';
To this: $config['uri_protocol'] = 'REQUEST_URI';


After I enabled rewrite_module I made a .htaccess file in my www root.


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ignite_tonys/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>  


There it is. Now I have shorter URIs and I don't have to see the /index.php/ in any of the URIs in my application.