Sunday, June 27, 2010

Where Is The Poptropica Bumble Bee Costume

Click and Context Menu on ListView

Continuing to play with the ListView, we see how to capture click on items in the list and how to display a context menu on a long click.




Capturing a click on an Item of ListView

Similar to button clicks, you define a listener to click on an item and then binds to the ListView.

In our case we will show a toast with the position and id of clicked (a Toast is a warning that appears in superimposed individually and then disappears).

This code:

 AdapterView.OnItemClickListener mItemListener = new 
OnItemClickListener () {public void
onItemClick (AdapterView parent, View v, int pos, long id) {String st =
"Clicked POS =" + id + " ID = "+ id;
Toast.makeText (getApplicationContext (), st,
Toast.LENGTH_SHORT). show ();

}};
((ListView) findViewById (R.id.taskListView))
. SetOnItemClickListener (mItemListener)


Showing context menu

We want that when you do a long click on a list item appears to be a context menu with the Cancel command, Edit, Delete.

First we define the IDs of the menu commands in the private data of the Activity.

 private static final int CANCEL_ID = Menu.FIRST; 
private static final int EDIT_ID Menu.FIRST = +1;
private static final int DELETE_ID Menu.FIRST = +2;

Then there is the ListView to manage ContextMenu.

 registerForContextMenu (findViewById (R.id.taskListView)); 

Then call override the functions that create the context menu and running the operation.


 @ Override public void 
onCreateContextMenu (ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu (menu, v, menuInfo)
menu.add (0, CANCEL_ID, 0, "Cancel");
menu.add (0, EDIT_ID, 0, "Edit");
menu.add (0, DELETE_ID, 0, "Delete");}


@ Override public boolean
onContextItemSelected (MenuItem item) {info =
AdapterContextMenuInfo (AdapterContextMenuInfo) item.getMenuInfo ();
switch (item.getItemId ()) {case
CANCEL_ID:
return true;
homes EDIT_ID:
Toast.makeText (getApplicationContext (), "info.position =" +
info.position, Toast.LENGTH_SHORT). Show ( )
return true;
homes DELETE_ID:
data.remove (info.position)
adapter.notifyDataSetChanged ();
return true;
default: return
super.onContextItemSelected (item);}

}

As you can see the gate is to immediately close the menu, the Edit view for now a toast with information about the item clicked, performs the cancellation Delete item from the database and notifies the adapter that needs to update the ListView before returning to the main Activity.

Pedestal Sinks Towel Bar Ontario

Create a daughter Activity (with code) Create a

In the previous post Create an Activity daughter I posted the explanation in the form of two wave that Google had used during the study. But I noticed that the requirements are very stringent browsing, so that is not visible on mobile devices. Better then repeat the post in normal form.


ANDROID: CREATION OF A DAUGHTER ACTIVITY

Purpose: I have a demo application based on ListView and SimpleAdapter and I have to enter a dialog modal that allows me to insert new data into the ListView.

Study and Documentation:
  • How to integrate the new class in the Activity
  • Recalling the time button to the Activity chosen
  • Two options for handling data
    • Inserting data into the database made by Activity secondary and primary updates the data entry View
    • Activity in primary care receiving crude from the secondary (best)

RECALLING THE ACTIVITY

1) It is declared as private member of a handler in the Activity primary ADD button, the value of the initialized at OnCreate.

private Button mAddAccountButton;



public void onCreate (Bundle savedInstanceState)
{
...
mAddAccountButton = (Button) findViewById ( R.id . AddContactButton)



2) There is an OnClick Listener which launches a special member function of private primary Activity.

mAddAccountButton.setOnClickListener (new View.OnClickListener () {

public void onClick (View v) {
launchContactAdder ();

}});


3) The member function to launch the secondary creates a new Activity Intent with reference to the same sub-class of the Activity. Then start this Activity.

protected void launchContactAdder () {

Intent i = new Intent (this, ContactAdder.class)
startActivity (i);
}

how to integrate the class in

1) Create a standard layout to be invoked after the Class Activity


http://schemas.android.com/apk/res/android "
android: orientation =" vertical "
android: layout_width = "fill_parent"
android: layout_height = "fill_parent">



android: text = "PROVAAAAAA"
android: layout_width = " wrap_content "
android: layout_height =" wrap_content " />

android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "A" />

android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "DUE" />




2) Create a new file with JAVA in the general declaration of an activity.

TaskAdder extends Activity {public class

/ / private ArrayList > data;
/ private / adapter SimpleAdapter;

/ ** Called When the activity is first created. * /
@ Override public void
onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState)
setContentView (R.layout.taskadder);}

}

3) it must be held inside the MANIFEST the new Activity, just below the main application.


android: label = "@ string / app_name">


DATA MANAGEMENT

He said there were two options, to manage data storage at the primary or secondary activity .

Seeing some examples, such as Notepad to Google, it seems that the trend is to manage all the secondary activity, so that when you return to the primary is all perfectly consistent. It may make sense, so you avoid double validation data, and the fragmentation of operations on data in two different activity (less interdependence).

In any case, deserves to be printed using the example ContactManager http://www.anddev.org


ANDROID: MOVE DATA BETWEEN ACTIVITY

The next step that has created a secondary activity is to pass data back and forth between the same Activity.

Overview: Google http://developer.android.com/guide/appendix/faq/framework.html FAQ # 3

There are three classes of data:
  • Primitives: directly using the method putExtra intent
  • not persistent use application public static, singleton, hashmap of weakreferences
  • Persistent: using preferences, files, SQLiteDB, ContentProvider

For the first version of the test application will use public static with non-persistent data, which allows me to make the least changes possible. Virtually call the public static variable calling it up and then use it externally nomeclasse.nomevar .

Here we are implementing.

As mentioned earlier the ideal is to make the databases, making them visible to every public static Activity.


Domo extends Activity {public class
public static ArrayList > data;
SimpleAdapter public static adapter;
...

After that Activity in the secondary is slightly modifies the code already tested in the primary by collecting the data to be entered from the graphical interface of the sub-Activity, where the user has paid to type.


/ / handle the click on the button ONE
View.OnClickListener mOneListener OnClickListener = new () {
public void onClick (View v) {
ET1 = alt text (alt text) findViewById ( R.id . editname)
et1.getText String st1 = (). toString ();
ET2 = edit text (alt text) findViewById ( R.id . edit date);
et2.getText String st2 = (). toString ();
HashMap taskMap = new HashMap ( )
taskMap.put (t_imgres "R.drawable.task_2)
taskMap.put (t_name ", st1);
taskMap.put (t_date", st2);
Domo.data.add (taskMap) / / put the hashmap listings
Domo.adapter.notifyDataSetChanged ();}

};


Button btnOne;
btnOne = (Button) findViewById ( R.id . btnTaOne)
btnOne.setOnClickListener (mOneListener);

Saturday, June 26, 2010

Beautiful Agony Group

Activity daughter

Once you learn to manage the primary interface of the Activity and its interaction with the user, it is natural to create an ADD button that opens a sub-Activity, a small window where the user can enter an individual given, then displayed in the main list.

It's time to create as a daughter Activity.

As an experiment I plug in the post GoogleWave I used while studying the code.



Thursday, June 24, 2010

Prom House Rentals In The Poconos

do without the final keyword

In the test mentioned in the last post I had to click on the button associated with inserting a new record in database and then notify the SimpleAdapter that the database had been modified and therefore would have had to redesign the ListView.

In doing so the compiler I had an error, because the classes of the database and the adapter were in fact instantiated in the OnCreate function, launched the application is started. The life cycle of these variables end with the end of the function itself, so when you click the button no longer exists, hence the error. The Eclipse compiler kindly provided the suggestion to turn in final these variables.

The keyword final Java use has varied and complex, as we are concerned say that we need to preserve the value of the variable once the function has finished its work and then you can use it in other functions .

anddev.it A comment received on the forum and found some hints as I documented and studied how to create the dialog, made me realize how do without the final: just its reporting the two variables as private members of the class , dare I say it a truism.

Monday, June 21, 2010

Acrostic Poem About Cellular Respiration?

Working with ListView and Adapter

In the very first Android application we saw how to create and manage a user interface, now it's time to move on to something more real and useful in some way, something to show you the underlying data.

Always on the legendary forum anddev.it I found a very simple tutorial, but enlightening. There is talk of manage a ListView with SimpleAdapter , and the idea is to have an array of data to be displayed in a list with custom layout with lots of specific icon for each element of the list. The picture on the side makes a thousand words.

The linked tutorial explains very well how to build the application, I would like to dwell only on the concept of Adapter , the generic type from which it was derived then our SimpleAdapter.

The purpose of an Adapter is to automate the bond that exists between the database and ListView which is the graphical display.

What we do is build a database in a timely manner, or we create an array of data in the form of a HashMap, and then build the Adapter past: the database, the template of the single view and how to map the fields in the database on those of the display.

eventually attack the adapter to the ListView and from that moment everything is automatic, ie when creating the list, the list itself will take the data from the database via the Adapter.

my A variant of this example was add a button and make that clicking an item was added to the list. Programmatically what I did was attach the OnClick event to add an item to the database and then use the member function notifyDataSetChanged the Adapter, which indicates that the database is varied.

Thursday, June 17, 2010

What's With The Court Wigs?

General

I was surfing the web looking for tutorials, presentations and general information about interesting for Android, and I come in PDF of formal presentations made by Google at the recent Google I / O.

Council very strongly to read some, because they are accessible to experts and reduction in detail on a very specific topic, which is ideal for those who want to start getting comfortable with the system.

stress in particular:

Monday, June 14, 2010

Inmate Visit Schedule On Rikers Island

very interesting travel companions

Learning to program for Android is not a joke, despite the simplicity of the first approaches. If the desire and determination is sufficient, the path that unfolds before us can lead to significant challenges. In these cases, having the fellow travelers is not only possible, but it is also advisable.

E 'for this reason that the second key step to do before tackling head-on Android programming is to find a community of people with the same passion and the same objectives .

In the past weeks I have tried and visited some 'forum on development for Android, I decided to enroll and take in reference http://www.anddev.it . It 's a very small community (at least for now), but the material is high quality and moderators are technically very smart.

Sunday, June 13, 2010

Danielle From Modeling Agency

First Steps with activity and view

When approaching for the first time a new platform (in this case, Android), especially if well away from the model of desktop PC, the question arises as will be made and whether their programming skills are still valid and useful. Could and should start by explaining the model of Android applications, how they interact with the system and all the theory related to it.

But this usually scares and discourages anyone other than an expert.

In these cases it is better to give up the accuracy and completeness of explanations, in favor of something limited and incomplete, but much easier and more fun . This will be the content of my explanation, nothing formal or crystal, only the bare minimum to keep you entertained.


Want to write an Android application but do not know where to start?

The simplest application Android you think of it as a screen of your mobile phone. Something that once launched, will display at full screen something written or drawn, and eventually is able to interact with the user (you can, but for now we do not care).

So the first thing to learn is to draw the screen startup Android.

For convenience we give a little 'names: the design of the screen is called view (in Italian view), the real engine of the application, that takes care to show the startup screen of' application is called activity (in Italian activities ).

The simplest of Android applications will be composed of:
  • a view: the description of the design of the screen real
  • an activity: the opening of the application, the view draws on the screen
Since the activity is very minimal (there just the one that appears by default when you start a new project), we see how to define a view.


Draw the view of an application

The view of an application is defined through an XML file that contains a description of what will be drawn on the screen. This topic is so important that there are specific tutorials Views on directly on the official Android, quick and easy tutorial that teaches the basics quickly.

Write the XML for a view implies two things:
  • Declare which elements design, buttons, text labels, images, etc..
  • organize the screen alignment, grids, lists, tables.

Take the example provided by the site called Android Hello their layout, which allows us to quickly explain what we're talking about. The example should look like in this picture.

Within the screen we want these items:
  • Text Label: TextView
  • text entry field: EditText
  • Two buttons: Button
for the organization (layout) want:
  • entry field under the label text
  • Button OK in the input field and right
  • Cancel button to the left of OK

This verbal description of the screen is easily translatable into XML. For the organization we put all the elements in a block called RelativeLayout , which means that we will describe the position of objects to each other (re-read the above organization and you will notice this).


Within it we will put the items cited above, also indicating the relative positions (highlighted in red the attributes that define them).



tools provided by Eclipse

We will skip the explanation of the other fields as unnecessary to understanding the exercise, the important thing is to have a working example from which you learn something , then the reader is trying to change it and see what happens. But it is not appropriate use the example to show the layout tools provided by Eclipse.

The description file of the screen is called main.xml and is located in the layout in turn contained in the res folder (resources = resources) application. Should become familiar with the hierarchical view of the application because it will make it much easier to maneuver in the future.

Double-clicking on the file name will open the text editor that allows us to modify the same file from inside Eclipse. On the right is a comfortable vision of the hierarchical elements in the screen including items used to organize them.


There is also an interactive graphical view of the layout that you are writing, which is activated by clicking view layout below. The graphical view is very convenient to have an overview of the layout, but will often be easier and faster action on the text file, once you're comfortable.


My advice now is to try to change this example, change something and see what effect it generates. Then try the other examples on the official site.

Learning to manage well the view is essential to enable them to write the actual application that does something more to show a screen.

Saturday, June 5, 2010

What Is The Best Teg To Use In A Generator

Install the Android Development Android

A key factor that made me choose Android as a platform on which to learn to develop, is the extreme simplicity and ease of installation development tools, download from the very first Hello World. I can try to retrace the steps taken by key http://developer.android.com/sdk/installing.html .

System Requirements

If you decide to develop on Windows platform, know that I performed the procedure on Windows XP SP3, very ancient operating system, so we can safely say that there are no requirements regarding the system operational.

Operating System: XP - Vista - MacOSX 10.5.8 - Linux
Disk Space: 1700 MB
Internet connection: at least during installation

Download installation packages

next step is to download the required installation packages, which are basically three: the Integrated Development Environment Eclipse, the Java Developer Kit and Android Software Developer Kit

the end the folder of downloaded packages should look like in this picture.



Installing packages

The order of installing packages is as follows:
  • JDK
  • Unzip the docs Eclipse JDK
  • Android SDK

Once completed, installations there are in fact other downloads that will be performed during configuration of the various packages.


Installing ADT plugin for Eclipse

This Eclipse plugin development system allows you to configure virtually Eclipse development platform Android, in a completely automatic.

To install: Open Eclipse
  • Help / Install New Software / Add ..
  • the dialog that opens put
    • Name: Android Plugin
    • Location: https: / / dl-ssl.google.com/android/eclipse /
  • you check the checkbox to Developer Tools and proceeds
  • Once finished restart Eclipse
  • Windows / Preferences / Android
  • You set the correct SDK Location
  • Confirm and you're done

Installation platforms


To install the platforms you need to run the configuration tool content nell'Android SDK, called Android SDK and AVD Manager directly from the Windows menu of Eclipse. In the main screen you must tick all items that are obsolete, so to download to your computer all platforms that Android will ever serve. At the end

installed packages will appear roughly as in the image below.



Next Steps

The official procedure for Android recommended as the next step to enter, compile and run the first application, following the Hello World tutorial . It 's very simple and fast, and makes sure you have correctly installed the entire system development.

Wednesday, June 2, 2010

Best Crabcakes In Maryland 2010



I have always liked the programming, a very young age. My first program was written in the ancient Commodore VIC-20, three lines of Basic that endlessly repeated phrase on the screen fixed. My first computer was a Commodore 64, where in the sixth grade writing programs to apply the theorem of Euclid. At first I found the world more than x86, and I started programming on a 286 with DOS 3.3, but the screen was monochrome wireframe graphics was more than enough. The university was the period of programming C + +, Win32 and the first approaches to HTML + CSS. Then there was a relatively long period of server-side web programming, mainly PHP + MySQL. I plan on working too, but in a completely different and uncorrelated, since it is completely focused on Verilog / VHDL.

Now is the time to change again, the tremendous potential of new mobile platforms. I refer to Smartphone and Tablet. Actually the first approach was just over 5 years ago, with the first phones with Access, but the excessive complication of the development tools as well as the fragmentation of device (And on compatibility) discouraged me from the start.

Recently, I also thanks to the incredible success of the iPhone + Appstore, I came back the desire. So I explored the landscape of opportunities.
  • iPhone was my first choice, either to the size of the market want the stability of the platform. Unfortunately I've come up against in the inevitable closure of Apple, required language (Objective-C), an obligation to join the developer program with its payment (not too), an obligation to use a Mac for development tools (the biggest problem ), uncertainty of the future (rules of the AppStore not completely known and clear).
  • Nokia Second choice would have been my favorite for the innate sympathy I have for Nokia and its products. I've really tried, with Maemo and then also with the QT-SDK. Two almost insurmountable problems that made me give up: too much fragmentation of devices and difficult to address the incredible development tools, too difficult to tame for me.
  • Android I had read many good things about Android and also much criticism, was the first last chance to rethink my approach to programming on mobile devices. At this point, my claims were dropped, I did not mind so much the Store, dissemination or fragmentation, I was interested in your base, that the development tools were accessible and usable for me (in the sense of my ability and knowledge). As I explain in a separate post, I went from complete novice (apart from a bit 'of Java that I already knew), I read the tutorial to install the development tools to the first classic Hello World. Less than two hours and was fully operational from scratch, all the toolchain working, from project creation to Run on the virtual device. Android won hands down.

What do you want to be this BLOG

This blog is the diary of my exploration of the universe Android . I do not know anything about Android, I have fair knowledge programming newbie like me to explain all the right steps (a few) and wrong (many) that I will. Do not be severe in judgments, I do it for fun, make mistakes and wasting time is not a problem for me when it's a hobby. However, write reviews and comments are welcome. :)


Delusions and idiosyncrasies

I firmly believe that you learn about a person when you begin to appreciate or despise certain fixations or idiosyncrasies. Even I know I have some many.
  • I do not like tabs, I prefer the space, namely 3
  • Almost all editors have as default Courier 10pt, I'm always 8pt
  • What are they waiting to put in the column-edit all editors?
  • I do not like to waste a whole line just to open the clip alone {
  • I genetically unable to write file names with spaces
  • hate code files that exceed the three screens in length
  • 99% of programmers can not indent your code
  • comments mainly serve to make the code more readable graphic
  • The object-oriented programming is often used inappropriately
  • I have an almost religious attention not to waste bytes (legacy HDL)
  • Since a role to play, fewer lines of code are written, there will be fewer bugs
  • ... others will follow as I will have in mind