Feeds:
Posts
Comments

In my current project i was ask to: if a user wants to cancel, lets say a web service from retrieving information (sometimes these are heavy operations, and take some time and the user may not want to wait), the only thing he would need to do was to tap the “Back” button. Although is pretty simple to just set a progressDialog “cancelable” (when you click the “Back” button the progressDialog will disappear), if you want to, for example, stop a thread that is running while the progressDialog is showing, you need to make something else:

1:

progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(this);

With this, you are saying that the progressDialog can be canceled, and also you are going to create a Listener for the “cancel action”. Note that we are going to use our activity as the listener (note the “this” inside the ()).

2. We are you going to add  an implementation to our activity, so its able to listen to that kind of actions:

public class YourClass extends Activity implements  OnCancelListener

3. Finally we override this method (note you may get an error when you implement OnCancelListener, but you can resolve it, by adding the method onCancel):

@Override
public void onCancel(DialogInterface arg0) {
//your code goes here.
}

4. So when you press the “Back” button, the onCancel method will trigger and you can stop/cancel/save anything that you want along with the dismiss of the progressDialog.

Hope it helps. :)

First of all, i’m sorry for the huge delay but the most important thing right now is: we are back!

I am not gonna post about C# or ASP.NET at least in the next posts. Not because i chose like that, but life just took me on another way.

I’m gonna talk about a few things i’ve been learning about Oracle Database.

Let’s start by Explain Plans. Do you know what it is? Well, i didn’t until a few days ago. Started learning about it and decided to make a post. Hope it’s useful to somebody.

Explain plans exist to show you the background step by step for Oracle to run the query, this will allow you to optimize your queries.

Let’s see an example.

I created two tables called ‘teste_a’ and ‘teste_b’ with 3 columns each. ‘Teste_a’ has ‘Column_a’ as a VARCHAR and primary key, ‘Column_a2′ as a number.

‘Teste_b’ has ‘Column_b’ as a VARCHAR and primary key, ‘Column_b2′ as a number and ‘Column_a’ as a VARCHAR and foreign key referencing ‘Teste_a’ table.

Then added some records into both tables.

Now let’s see what Oracle the background of running the simple query : ‘select * from teste_a;

For that, we need to create the explain plan with the following code:

explain plan for select * from teste_a;

And display the explain plan with the following code:

select plan_table_output from table(dbms_xplan.display());

The Result was:

This shows us that the plan for execute that query, is quite simple. We read Explain Plans from the bottom-up, so the first step Oracle will do is to get Full Table Access for that table. There are several ways to get data from a table. Full Access is the longest because it gets every record from that table. You can find a table using indexes which normally is the fastest way if the indexes are unique ( like primary keys ).

When you are managing tables with millions of records you don’t want Full Access to every table because it might keep the query running forever.

Now let’s join data from both tables too see what happens.

explain plan for select * from teste_a a1,teste_b b1 where a1.column_a=b1.column_a;

select plan_table_output from table(dbms_xplan.display());

The result:

Here Oracle found the ‘teste_a’ table through the primary key INDEX. Then had full access to the second table.

Then we can see a  Nested Loops line. This means there is a join between tables. Will get it more detailed later.

This is just an introduction to Explain Plans.

I’m just starting with this, so i’ll get to you with this subject and more examples later.

See you guys soon!

The image…

I thank Luís for the idea of using this image… Because every programmer has his own windmills to fight…

Long time no see…

I know i have been away for some time now…  sorry about that… I will try to post more often. For professionals reasons, i will talk about android ( Java, yupi….). My colleague and friend will also post as he can. So, Hello World, Android:

DropDownList Issue, how do you select an item that isn’t there yet?

Answer: FindByText or FindByValue, like the next example.

Imagine that you have a dropdownlist that will be filled with names for DataText  and numbers for DataValue somewhere in the code. You need to do something like this:

DropDownList1.Items.FindByText(“Alan”).Selected = true; or

DropDownList1.Items.FindByValue(Convert.ToString(1)).Selected = true;

Hope it’s useful.

In this example, i will show how to add a google’s maps to your aps.net application.

  1. You can start by creating a new ASP.NET website.
  2. Add the following code in the “source view” mode (the sentences in black are there by default, you just need to had the red ones):

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<%@ register  assembly=”GMaps”  namespace=”Subgurim.Controles”  tagprefix=”cc1″  %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

(…)

<body>

<form id=”form1″ runat=”server”>
<div>

<cc1:GMap ID=”GMap1″ runat=”server”
key=”??????????????????????????????????????????????????????????????????????????????????”

Font-Bold=”True” onclick=”GMap1_Click”/>

// In the “????”, you will add your own key. You can get it here: http://code.google.com/intl/pt-PT/apis/maps/signup.html

(…)

So, basically, you are adding the map to your website with this code. Unfortunately, you cant do much with it. So we are adding a few basic controls to it. You can add the next code inside your *.cs file, inside the Page_Load method:

GMap1.Width = 500;
GMap1.Height = 300;
GMap1.mapType = GMapType.GTypes.Satellite;
GMap1.addControl(new GControl(GControl.preBuilt.GOverviewMapControl));
GMap1.addControl(new GControl(GControl.preBuilt.LargeMapControl));
GMap1.addControl(new GControl(GControl.preBuilt.MapTypeControl));

GLatLng portugal = new GLatLng(39.639538, -7.844238);
GMap1.setCenter(portugal, 6);

I wont talk about these controls, that”s not the point of this post. The objective of this post, is to get you started using Google Maps techology. In the next post, i will talk about this:

  1. Having a data base with a few coordenates.
  2. Retrieving that data with a webservice.
  3. Adding  points, to the map, using those coordenates.
  4. Add information to those points (for example, a description of yours, also retrieved from the database)

If you want to get going and explore the tool, i advice you this:  http://en.googlemaps.subgurim.net/

Have fun. :)

So you have a Gridview and you want to turn the rows into clickable rows to redirect to another page without using the ‘Select’ command field? Here is what you’ll have to do:

Create the RowDataBound event of the Gridview by going to the Gridview properties, selecting ‘Events’ and then clicking twice on the RowDataBound event and it will automatically create the event.

Now you’ll have to do something when each row is bound with some data in the Gridview.

Inside of the created method you put the next lines:

if (e.Row.RowType == DataControlRowType.DataRow)

{
e.Row.Attributes.Add(“onclick”, “window.location=’something.aspx’”);
}

Now if you want to pass some value ,you should put it next to the ‘aspx’, like the next example.

e.Row.Attributes.Add(“onclick”, “window.location=’something.aspx?id=10′”);

Remember, you always have to put the ‘?’ next to the ‘aspx’ and only after that,you put the name and the value of the variable you want to pass.

If you want to pass more than one variable you should put the ‘&’ between them, like the example below.

e.Row.Attributes.Add(“onclick”, “window.location=’something.aspx?id=10&name=john’”);

Now you’re on the ‘something.aspx’ page and you want to retrieve those values. All you have to do, for example on the page load(or whatever you want) is:

int id = Convert.ToInt32(Request.QueryString["id"]);

string name = Convert.ToString(Request.QueryString["name"]);

I hope this helps, and if by some reason it doesn’t work, let me know.

Follow

Get every new post delivered to your Inbox.