[android-developers] onClickListener for on a listView

2010-09-06 Thread kingh32
Hello

I've got some code that pulls pulls in data from a database via a PHP
service layer using JSON etc and displays it as a listview.
It works and I'm very happy with it - but I wanted to add an
onClickListener to it.

I know how to do it for buttons but its proving more difficult for the
list view.

I basically want it to take the ID taken from the JSON and put it into
an intent to another activity.

This is my class...

public class OnlineScores extends Activity
{
/** ListView that holds item references */
ListView li;

/**
 *Array adapter that will hold an ArrayList of invoked items
 *and display these in the ListView
 */
EventAdapter arrayAdapter;
String eventURL;

/** Houses the invoked items */
ArrayListEvent a = new ArrayListEvent();
@Override

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.lmain);
Intent intent = this.getIntent();
Bundle b = intent.getExtras();
eventURL = b.getString(URL);

//Initialise ListView
li=(ListView)findViewById(R.id.lstText);
arrayAdapter = new 
EventAdapter(OnlineScores.this,R.layout.list,a);

// Set above adapter for the ArrayList
li.setAdapter(arrayAdapter);

// Create an object of the GetData class
GetData g = new GetData();
String response = g.getIt(,,eventURL);

try
{
// Put JSON response into an object
Type collectionType = new TypeTokenArrayListEvent()
{}.getType();

List Event lst= new Gson().fromJson(response, 
collectionType);

for(Event l : lst)
{
a.add(l);
}
// Inform the ArrayAdapter of the change from ArrayList 
to List
arrayAdapter.notifyDataSetChanged();
}
catch(Exception e)
{

}
}
}

I'm trying to implement this...

lstText.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
 @Override
 public void onItemClick(AdapterView? a, View v, int 
position,
long id)
 {
 // Do stuff here
 }
 });

but I'm being told to remove the @Override statement AND to inherit
abstract methods.

Any ideas?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Programming a target in an Android Application

2010-09-06 Thread kingh32
Thought I would post back and say thanks for helping me program the
target.
It was very straightforward in the end. And if someone else 'Googles'
it in the future this is bound to come up!

Identify the centre point, then use the X and Y coordinates of it as a
correction factor
Use Pythagoras theorem  to calculate the hypotenuse of the triangle
i.e. the longest side of an imaginary triangle that exists based on
the coordinates
recorded when somebody touches the screen.
Award different points or do different things based on this length.

Cheers guys

On Aug 3, 9:47 pm, kingh32 horaceb1...@gmail.com wrote:
 Thanks, both of you for your help.
 I imagine I'll be back with more questions soon!

 On Aug 3, 8:08 pm, Bob Kerns r...@acm.org wrote:



  Everything -- both the positions and the image widget size -- will be
  in pixel coordinates. Actually, you don't need to know that -- just
  that they're the same. Hell, I could even be wrong; I'm not going to
  take out a microscope and check.

  If you have different coordinates for your image data (or even if you
  don't or don't know or might want to scale in the future or are
  paranoid), simply scale by the ratio of the image data : image widget.
  A scale factor of 1:1 won't cause you any trouble.

  There are times to be absolute, and times to be relative. This is one
  of the latter.

  On Aug 3, 9:25 am, kingh32 horaceb1...@gmail.com wrote:

   Hello - Thanks for your reply!

   What you have just mentioned is pretty much where I'm stuck!
   I don't know how to identify programatically where the target actually
   is. Would this be done using pixel coordinates?
   Is there a way to determine the resolution of the phone (screen) that
   the app is being run on and adjust these calculations accordingly?

   Thanks

   On Aug 3, 4:52 pm, TreKing treking...@gmail.com wrote:

On Tue, Aug 3, 2010 at 4:05 AM, Horace Bell-Gam 
horaceb1...@gmail.comwrote:

 No, so far all I've been able to do is overlay an image of the target 
 and
 make the entire object respond to a click.

You know:
- The center of the image
- The length of each band
- Where the user clicks on the image (via onTouchEvents, me thinks)
- Simple algebra to calculate the distance of a point from the center 
of the
image (I hope)

That's all you should need to figure out which band the user has 
touched.

What have you tried thus far? Where are you stuck?

---
 --
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-05 Thread kingh32
I tried this and... it works!

Thank you for your help, it now displays a list of the the most recent
update to the database.
(only one item in the list) but for now this will do.

Many thanks

On Sep 4, 5:55 pm, Kostya Vasilyev kmans...@gmail.com wrote:
 Without the angle brackets, right?

 adb uninstall com.shootingrange

 Like that?

 --
 Kostya Vasilyev --http://kmansoft.wordpress.com

 03.09.2010 18:09 пользователь kingh32 horaceb1...@gmail.com написал:

 Yes that is definately what iI did, replace package with
 com.shootingrange

 On Sep 3, 3:03 pm, Kostya Vasilyev kmans...@gmail.com wrote:

    03.09.2010 17:58, kingh32 пишет:...

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers g...

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-03 Thread kingh32
Thanks for spotting the comma.
I've removed it but it still cites this query as an error.
In fact, no matter what I try to do the same error is displayed.
Even if I change the intent pointing to this class, to completely
different non database related class I still get this error and it
crashes.
How is this possible?

On Sep 3, 8:56 am, Kostya Vasilyev kmans...@gmail.com wrote:
   You have an error in the SQL for creating the table:

 03.09.2010 5:54, kingh32 пишет:

     + shotsPerRound, INTEGER

 The comma should be at the end shotsPerRound INTEGER,.  This misplaced
 comma causes the shooter column to not be created.

 Also, you really want to use parametrized queries for inserting bulk
 data, so instead of:

 db.execSQL(INSERT INTO tablename VALUES('a', 'b', 'c'));

 you want to be doing:

 db.execSQL(INSERT INTO tablename VALUES(?, ?, ?), new String[]{ valA, valB, 
 valC});

 -- Kostya

 --
 Kostya Vasilyev -- WiFi Manager + pretty widget 
 --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-03 Thread kingh32
Hello, I've sorted that problem now. I'm using adb to check that the
database gets made and it does.

I have this error now.

53): Starting activity: Intent { cmp=com.targetshooterapp/.
DBAdapter }
E/CursorWindow( 1354): Bad request for field slot 0,-1. numRows = 1,
numColumns
= 2
D/AndroidRuntime( 1354): Shutting down VM
W/dalvikvm( 1354): threadid=3: thread exiting with uncaught exception
(group=0x4
001aa28)
E/AndroidRuntime( 1354): Uncaught handler: thread main exiting due to
uncaught e
xception
E/AndroidRuntime( 1354): java.lang.RuntimeException: Unable to start
activity Co
mponentInfo{com.targetshooterapp/com.targetshooterapp.DBAdapter}:
java.lang.Ille
galStateException: get field slot from row 0 col -1 failed
E/AndroidRuntime( 1354):at
android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2401)

One of the two tables I'm trying to populate is not being populated.
Could this be the reason for this error?

On Sep 3, 11:49 am, Kostya Vasilyev kmans...@gmail.com wrote:
 Your database creation statements have if exists in them.

 Did you make sure the database actually got recreated?

 --
 Kostya Vasilyev --http://kmansoft.wordpress.com

 03.09.2010 14:36 пользователь kingh32 horaceb1...@gmail.com написал:

 Thanks for spotting the comma.
 I've removed it but it still cites this query as an error.
 In fact, no matter what I try to do the same error is displayed.
 Even if I change the intent pointing to this class, to completely
 different non database related class I still get this error and it
 crashes.
 How is this possible?

 On Sep 3, 8:56 am, Kostya Vasilyev kmans...@gmail.com wrote:

    You have an error in the SQL for...

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers g...

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-03 Thread kingh32
I cant get adb uninstall to work
I'm doing this

adb uninstall package
I've also tried

adb uninstall [-k]package and adb uninstall []package

In the mean time I've created another database and tried to populate
it with the new queries but it still tells me that I'm trying to
populate an 8 column table with 9 columns.

final String CREATE_TABLE_EVENT = CREATE TABLE IF NOT EXISTS
tbl_events(
+ entryID INTEGER PRIMARY KEY , 
+ eventName TEXT,
+ date TEXT,
+ eventType TEXT,
+ numRounds INTEGER,
+ shotsPerRound INTEGER
+ shooter TEXT,
+ distance TEXT,
+ totalScore INTEGER);;


String INSERT_INTO_EVENT = INSERT INTO tbl_events VALUES
 +(1,'
 + eventName
 +','
 + date
 +','
 + eventType
 +','
 + numRounds
 +','
 + shotsPerRound
 +','
 + shooter
 +','
 + distance
 +','
 + totalScore +');;

I've looked at these over and over and there are definitely 9 fields
in each.

I would like to change them to look like your example above but I dont
really understand this construct...

db.execSQL(INSERT INTO tablename VALUES(?, ?, ?), new String[]
{ valA, valB, valC});

What would I replace the question marks with - sorry if thats a really
silly question!
On Sep 3, 1:35 pm, Kostya Vasilyev kmans...@gmail.com wrote:
   I believe that one of the columns is still missing, so you get this
 error at one of these lines:

 cursor.getString(cursor.getColumnIndex(blah))

 Where getColumnIndex() returns -1, because the column is not in the
 query results, and getString() is being asked to get the data for column
 -1, which is invalid.

 - Change your getColumnIndex to getColumnIndexOrThrow, this will let you
 see which column is missing in the query

 - Cache column indices outisde the loop

 - Before running again, uninstall the application with adb uninstall
 to force the database to be recreated

 -- Kostya

 03.09.2010 15:24, kingh32 пишет:

  E/CursorWindow( 1354): Bad request for field slot 0,-1. numRows = 1,
  numColumns
  = 2

 --
 Kostya Vasilyev -- WiFi Manager + pretty widget 
 --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-03 Thread kingh32
It says that there was a syntax error in my command.

Thanks for the info on the ?s. Can imagine why its used, this looks a
mess!
Will try this now

On Sep 3, 2:51 pm, Kostya Vasilyev kmans...@gmail.com wrote:
   What does it mean that adb uninstall doesn't work? What is the error
 message?

 Are you using your actual package name instead of package?

 The question mark syntax is for being able to specify SQL statement
 parameters separately from the statement itself. This separates the SQL
 statement logic from the values. This is beneficial in several ways,
 which I will not go into right now.

 By using a question mark you're telling SQL that there is a value in
 this place, but it's specified separately, in the array (the last
 parameter).

 So you'd have:

 db.execSQL(
         INSERT INTO tbl_events VALUES (?,?,?,?,?,?,?,?,?),
         new Object[] { entryID, eventName, date,omitted , distance, 
 totalScore }
 );

 Better yet, specify which columns the values are for, like this:

 db.execSQL(
         INSERT INTO tbl_events (entryID, eventName, date,omitted)  +
          VALUES (?,?,?,?,?,?,?,?,?),
         new Object[] { entryID, eventName, date,omitted , distance, 
 totalScore }
 );

 -- Kostya

 03.09.2010 17:38, kingh32 пишет:





  I cant get adb uninstall to work
  I'm doing this

  adb uninstallpackage
  I've also tried

  adb uninstall [-k]package  and adb uninstall []package

  In the mean time I've created another database and tried to populate
  it with the new queries but it still tells me that I'm trying to
  populate an 8 column table with 9 columns.

  final String CREATE_TABLE_EVENT = CREATE TABLE IF NOT EXISTS
  tbl_events(
                             + entryID INTEGER PRIMARY KEY , 
                     + eventName TEXT,
                     + date TEXT,
                     + eventType TEXT,
                     + numRounds INTEGER,
                     + shotsPerRound INTEGER
                     + shooter TEXT,
                     + distance TEXT,
                     + totalScore INTEGER);;

  String INSERT_INTO_EVENT = INSERT INTO tbl_events VALUES
                              +(1,'
                              + eventName
                              +','
                              + date
                              +','
                              + eventType
                              +','
                              + numRounds
                              +','
                              + shotsPerRound
                              +','
                              + shooter
                              +','
                              + distance
                              +','
                              + totalScore +');;

  I've looked at these over and over and there are definitely 9 fields
  in each.

  I would like to change them to look like your example above but I dont
  really understand this construct...

  db.execSQL(INSERT INTO tablename VALUES(?, ?, ?), new String[]
  { valA, valB, valC});

  What would I replace the question marks with - sorry if thats a really
  silly question!
  On Sep 3, 1:35 pm, Kostya Vasilyevkmans...@gmail.com  wrote:
     I believe that one of the columns is still missing, so you get this
  error at one of these lines:

  cursor.getString(cursor.getColumnIndex(blah))

  Where getColumnIndex() returns -1, because the column is not in the
  query results, and getString() is being asked to get the data for column
  -1, which is invalid.

  - Change your getColumnIndex to getColumnIndexOrThrow, this will let you
  see which column is missing in the query

  - Cache column indices outisde the loop

  - Before running again, uninstall the application with adb uninstall
  to force the database to be recreated

  -- Kostya

  03.09.2010 15:24, kingh32 пишет:

  E/CursorWindow( 1354): Bad request for field slot 0,-1. numRows = 1,
  numColumns
  = 2
  --
  Kostya Vasilyev -- WiFi Manager + pretty widget 
  --http://kmansoft.wordpress.com

 --
 Kostya Vasilyev -- WiFi Manager + pretty widget 
 --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-03 Thread kingh32
Yes that is definately what iI did, replace package with
com.shootingrange

On Sep 3, 3:03 pm, Kostya Vasilyev kmans...@gmail.com wrote:
   03.09.2010 17:58, kingh32 пишет: It says that there was a syntax error in 
 my command.

 I think it's useful to learn.

 Use adb uninstall your package name here

 So if your code is in package org.knigh32.ShootingRangeStats, you'd do
 this:

 adb uninstall org.knigh32.ShootingRangeStats

 --

 Kostya Vasilyev -- WiFi Manager + pretty widget 
 --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-02 Thread kingh32
 the to array, so each column in the from array is mapped to a view.

 To display two (or more) tables, you use something called a table
 join. It's a standard SQL construct, Google for it.

 Finally, use logcat (in Eclipse or adb logcat on the host computer) to
 see more detailed information whenever your application crashes.

 Including the Java stack trace from logcat output with your questions is
 also useful, as it helps others understand what goes on in your application.

 -- Kostya

 01.09.2010 20:26, kingh32 пишет:

            // Set the list adapter
            String[]from = {DBHelper.COL_ENTRYID,
  DBHelper.COL_EVENTNAME,
                      DBHelper.COL_DATE, DBHelper.COL_EVENTTYPE,
  DBHelper.COL_NUMROUNDS,
                             DBHelper.COL_PLAYSSPERROUND, 
  DBHelper.COL_PLAYERS,
  DBHelper.COL_DISTANCE,
                                     DBHelper.COL_TOTALSCORE};

            int[]to = {R.id.the name of my textview};

           // Put retrieved data into a list view
           SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
  android.R.layout.simple_list_item_1, cursor, from, to);

 --
 Kostya Vasilyev -- WiFi Manager + pretty widget 
 --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: SQLite implementation - need help!

2010-09-02 Thread kingh32
Just to add, it gives me the same error even when i completely change
the query and remove the apparently non existent column.
I'm really confused!

On Sep 3, 2:43 am, kingh32 horaceb1...@gmail.com wrote:
 Thank you for both of your replies. I have tried implementing both of
 your suggestions but neither has worked.
 I've found another way to do it though and I've had some success
 although displaying it as a listview seems to be really difficult.

 This is what I've written...

 package com.targetshooterapp;

 public class DBAdapter extends ListActivity
 {
         // These variables to be retrieved from the Intent Bundle

         /** Unique ID assigned to competitors once entering an event */
         int entryID;
         /** Unique identifier for shots */
         int shotID;
         /** Name of the event */
         String eventName=Tester;
         /** Event Date */
         String date=Date;
         /** Type of event */
         String eventType=Service Pistol;
         /** Number of rounds */
         int numRounds=1;
         /** Number of shots per round */
         int shotsPerRound=4;
         /** Name of user */
         String shooter=me;
         /** Distance from the target */
         String distance=100 yards;
         /** Total score at the end of the event*/
         int totalScore=10;
         /** x coordinate of user input on screen */
         float xCoord = (float) 345.675;
         /** y coordinate of user input on screen */
         float yCoord = (float) 345.675;
         /** Event table - String name */
         private final String EVENT_TABLE = tbl_event;
         /** Shot table - String name */
         private final String SHOT_TABLE = tbl_event;

         SQLiteDatabase db;
         public void onCreate(Bundle savedInstanceState)
         {
                 super.onCreate(savedInstanceState);
                 // Create Array List to store result
                 ArrayListString result = new ArrayListString();
                 try
                 {
                         db = openOrCreateDatabase(shootnext.db,
 SQLiteDatabase.CREATE_IF_NECESSARY, null);
                         // Set DB version, Locale and locking properties of 
 the database
                         db.setVersion(1);
                         db.setLocale(Locale.getDefault());
                         db.setLockingEnabled(true);

                         /** SQL query to create the event table */
                         final String CREATE_TABLE_EVENT = CREATE TABLE IF 
 NOT EXISTS
 tbl_event(
                                 + entryID INTEGER PRIMARY KEY , 
                         + eventName TEXT,
                         + date TEXT,
                         + eventType TEXT,
                         + numRounds INTEGER,
                         + shotsPerRound, INTEGER
                         + shooter TEXT,
                         + distance TEXT,
                         + totalScore INTEGER);;

                         /** SQL query to create the shot table */
                         final String CREATE_TABLE_SHOT = CREATE TABLE IF NOT
 EXISTS tbl_shot(
                         + shotID INTEGER PRIMARY KEY , 
                         + entryID INTEGER,
                         + xCoord FLOAT,
                         + yCoord FLOAT,
                         + points INTEGER,
                         + shooter TEXT);;

                          // Create tables in the database
                          db.execSQL(CREATE_TABLE_EVENT);
                          db.execSQL(CREATE_TABLE_SHOT);

                          // SQL query to enter event details into database
                          String INSERT_INTO_EVENT = INSERT INTO tbl_event 
 VALUES
                                  +(5,'
                                  + eventName
                                  +','
                                  + date
                                  +','
                                  + eventType
                                  +','
                                  + numRounds
                                  +','
                                  + shotsPerRound
                                  +','
                                  + shooter
                                  +','
                                  + distance
                                  +','
                                  + totalScore +');;

                          String INSERT_INTO_SHOT = INSERT INTO tbl_shot 
 VALUES
                                  +(17,'
                                  + 34 +','
                                  + xCoord +','
                                  + yCoord +','
                                  + totalScore +','
                                  + shooter +');;

                          //db.execSQL(INSERT_INTO_EVENT);
                          //db.execSQL(INSERT_INTO_SHOT);

                          Cursor cursor = db.rawQuery(SELECT 
 eventName,shooter

[android-developers] SQLite implementation - need help!

2010-09-01 Thread kingh32
Hello All

I'm stuck on an SQLite problem and have been for the past few day so I
thought I would share it with you.
All I'm trying to do is create an SQLite database to display the data
generated by the use of my app.

I've managed to get the app to send data to a MySQL database (quite
easily) but for some reason I'm finding this really difficult.

I've made a DB helper class which creates the database and adds one
table to it. I would like to create two tables but achieving one table
for now would be great!

public class DBHelper extends SQLiteOpenHelper
{
// Database constants
private static final String DB_NAME=ScoreStore;
private static final int DB_VERSION = 1;

public static final String TABLE_EVENT = event;
public static final String COL_ENTRYID = entryID;
public static final String COL_EVENTNAME = eventName;
public static final String COL_DATE = date;
public static final String COL_EVENTTYPE = eventType;
public static final String COL_NUMROUNDS = numRounds;
public static final String COL_PLAYSPERROUND = shotsPerRound;
public static final String COL_PLAYER = player;
public static final String COL_DISTANCE = distance;
public static final String COL_TOTALSCORE = totalScore;

public DBHelper(Context context)
{
super(context, DB_NAME, null, DB_VERSION);
// TODO Auto-generated constructor stub
}

/** Database created for the first time */
@Override
public void onCreate(SQLiteDatabase db)
{
   String sql = create table+TABLE_EVENT+
(_id integer not null primary key autoincrement,+
COL_ENTRYID + integer, +
COL_EVENTNAME + varchar, +
COL_DATE + date, +
COL_EVENTTYPE + varchar, +
COL_NUMROUNDS + integer, +
COL_PLAYSPERROUND + integer, +
COL_PLAYER + varchar, +
COL_DISTANCE + varchar, +
COL_TOTALSCORE + integer, );


db.execSQL(sql);
}

 /** Updates the database based on version id */
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion)
{

}
}



Then when I want to add data to the DB I use this code...


 DBHelper dbHelper = new DBHelper(this);
 SQLiteDatabase db = dbHelper.getWritableDatabase();

 //Load data
 Cursor cursor = db.query(DBHelper.TABLE_EVENT, null, null,
null, null, null, null);
 startManagingCursor(cursor);

 // populate the database
ContentValues values = new ContentValues();
values.put(DBHelper.COL_EVENTNAME, Test name);
values.put(DBHelper.COL_DATE, Today);
values.put(DBHelper.COL_EVENTTYPE, Test type);
values.put(DBHelper.COL_NUMROUNDS, 1);
values.put(DBHelper.COL_PLAYSPERROUND, 4);
values.put(DBHelper.COL_PLAYER, Tester);
values.put(DBHelper.COL_DISTANCE, 100 yards);
values.put(DBHelper.COL_TOTALSCORE, 45);
db.insert(DBHelper.TABLE_EVENT, null, values);

 // Set the list adapter
 String[]from = {DBHelper.COL_ENTRYID,
DBHelper.COL_EVENTNAME,
 DBHelper.COL_DATE, DBHelper.COL_EVENTTYPE,
DBHelper.COL_NUMROUNDS,
DBHelper.COL_PLAYSSPERROUND, 
DBHelper.COL_PLAYERS,
DBHelper.COL_DISTANCE,
DBHelper.COL_TOTALSCORE};

 int[]to = {R.id.the name of my textview};

// Put retrieved data into a list view
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, cursor, from, to);
setListAdapter(adapter);
registerForContextMenu(getListView());

The app runs fine until I try any of the above, then it just crashes.
2 1/2 Questions...

What am I doing wrong? Is what I'm doing hopelessly, completely
incorrect?
Once I've fixed this, how do I make it work for two tables?

Any help would be very much appreciated.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Passing variables using intents

2010-08-25 Thread kingh32
Thank you for your reply.

I had this code - roundVal =
(TextView)findViewById(R.id.TextViewRound); further down in the code
but as you said, where I was trying to setText roundVal had not yet
been initialised.

Thank you for pointing this (rookie mistake) out - I will sort out the
variable names now!

On Aug 25, 8:07 am, Kostya Vasilyev kmans...@gmail.com wrote:
   25.08.2010 5:12, kingh32 пишет:          
 //round.setText(String.valueOf(round));  The app crashes if I
  include this line, I've tried it for all of the variables

 I don't see a variable named round.

 There is roundVal, but it's not initialized, and is therefore null.
 You should add code to call findViewById() somewhere after
 setContentView and before the variable is used.

 The call String.valueOf() should use rounds, which is where you store
 the value gotten from intent, not round, which is supposedly the view
 where this value should be displayed.

 I also suggest you come up with some kind of consistent naming scheme
 for your variables, that makes typos like the above less likely.

 --
 Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Passing variables using intents

2010-08-25 Thread kingh32
Would you happen to know what it means if when trying to do a setText
the data shows as either null or a blank?
Thank you

On Aug 25, 8:07 am, Kostya Vasilyev kmans...@gmail.com wrote:
   25.08.2010 5:12, kingh32 пишет:          
 //round.setText(String.valueOf(round));  The app crashes if I
  include this line, I've tried it for all of the variables

 I don't see a variable named round.

 There is roundVal, but it's not initialized, and is therefore null.
 You should add code to call findViewById() somewhere after
 setContentView and before the variable is used.

 The call String.valueOf() should use rounds, which is where you store
 the value gotten from intent, not round, which is supposedly the view
 where this value should be displayed.

 I also suggest you come up with some kind of consistent naming scheme
 for your variables, that makes typos like the above less likely.

 --
 Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Passing variables using intents

2010-08-24 Thread kingh32
Hello

I am trying to pass some variables from a spinner to be displayed in
the following activity but whenever I do
variable.setText(String.valueOf(thing)); my app crashes.

This is my intent

Intent s= new Intent(NewCompetition.this,Target.class);
s.putExtra(rounds,round);
s.putExtra(attempts, attempt);
s.putExtra(distance, distance);
s.putExtra(tool, tool);

I have checked the status of these variables in the parent activity
and they display fine.

In the child activity...

public class Target extends Activity
{
/** Called when the activity is first created. */

private TextView name, attVal, scoreVal, attMax, roundVal, roundMax;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.target);

Intent intent = this.getIntent();
Bundle b = intent.getExtras();
String rounds = b.getString(rounds);
String shotround = b.getString(attempts);
String distance = b.getString(distance);
String firearm = b.getString(tool);
//round.setText(String.valueOf(round));  The app crashes if I
include this line, I've tried it for all of the variables
   }

}

If anybody could offer ant advice it would be very much appreciated.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: connect to sql server

2010-08-23 Thread kingh32
Hello I'm new to this too but I've managed to find a way to send and
receive data using a php script.

To send I have used this method

public void Post() throws ClientProtocolException, IOException
{
/** Connect with the PHP script */
String address = http://www.yourwebsite.com/script.php;;
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(address);
/** Set Post data - use an array of name value pairs */
ArrayListNameValuePair entry = new ArrayListNameValuePair();
/** Add these values */
entry.add(new BasicNameValuePair(key, value));
entry.add(new BasicNameValuePair( Id_Famille, Johnson));
post.setEntity(new UrlEncodedFormEntity(entry));

/** Execute post request */
HttpResponse response = client.execute(post);
}

To receive data I have used this class...

public String get()
{
String entityContents=;
InputStream is = null;
try
{
// Connect to PHP script
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new 
HttpGet(http://www.yourwebsite.com/
script.php);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();

byte buffer[] = new byte[1024] ;
is = entity.getContent() ;
int numBytes = is.read(buffer) ;
is.close();

entityContents = new String(buffer,0,numBytes) ;
Log.d(xxx,entityContents);

}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return entityContents;
}

I am at the stage where I need to convert the returned entityContents
value into a string without all of the json stuff around it.
The output looks like this...

[{key:value}]

and all I want is the value.
If anyone knows how - that would be useful!

On Aug 18, 12:51 pm, khalfaoui ameni khalfaoui.am...@gmail.com
wrote:
 thanks Sarwar Erfan for your answer,but can you tell me how i write
 the script and where i put it ??
 i tried to write a php script

 ?php
 $myServer = 98.130.0.21;
 $myUser = ;
 $myPass = **;
 $myDB = ##;

 //connection to the database
 $dbhandle = mssql_connect($myServer, $myUser, $myPass)
   or die(Couldn't connect to SQL Server on $myServer);

 //select a database to work with
 $selected = mssql_select_db($myDB, $dbhandle)
   or die(Couldn't open database $myDB);

 //declare the SQL statement that will query the database
 $query = SELECT Id_Famille, Id_filiale, Designation ;
 $query .= FROM T_Article ;

 while($e=mssql_fetch_assoc($query))
         $output[]=$e;

 print(json_encode($output));

 //close the connection
 mssql_close($dbhandle);
 ?
 and i put my scipt in my pc c:/
 in my application i write this :
  String result = ;

       ArrayListNameValuePair nameValuePairs = new
 ArrayListNameValuePair();

       InputStream is = null;
       //http post
       try{
               HttpClient httpclient = new DefaultHttpClient();
               HttpPost httppost = new HttpPost(http://10.0.2.2/
 getAllArticle.php);

               HttpResponse response = httpclient.execute(httppost);
               HttpEntity entity = response.getEntity();
               is = entity.getContent();
       }catch(Exception e){
               Log.e(log_tag, Error in http connection
 +e.toString());
       }
       //convert response to string
       try{
               BufferedReader reader = new BufferedReader(new
 InputStreamReader(is,iso-8859-1),8);
               StringBuilder sb = new StringBuilder();
               String line = null;
               while ((line = reader.readLine()) != null) {
                       sb.append(line + \n);
               }
               is.close();

               result=sb.toString();
       }catch(Exception e){
               Log.e(log_tag, Error converting result
 +e.toString());
       }

       //parse json data
       try{
               JSONArray jArray = new JSONArray(result);
               for(int i=0;ijArray.length();i++){
                       JSONObject json_data = jArray.getJSONObject(i);
                       Log.i(log_tag,id_famille:
 +json_data.getString(Id_Famille)+
                               , id_filiale:
 +json_data.getString(Id_filiale)+
                               , designation:
 

[android-developers] Re: connect to sql server

2010-08-23 Thread kingh32
Also, the PHP script should take request variables e.g.

?php

//connect to server
$connect = mysql_connect(host,user,password);
//connect to database
mysql_select_db(db_name);
//query the database
$query=mysql_query(

INSERT INTO  `db_name`.`table_name`
(`name` ,
`flag`)
VALUES ( '.$_REQUEST['key'].',  '.$_REQUEST['key'].')
);


print(json_encode($output));

mysql_close();

?

Key should match the key in the NameValuePair  key in your java code.

I hope this helps

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Programming a target in an Android Application

2010-08-03 Thread kingh32
Hello - Thanks for your reply!

What you have just mentioned is pretty much where I'm stuck!
I don't know how to identify programatically where the target actually
is. Would this be done using pixel coordinates?
Is there a way to determine the resolution of the phone (screen) that
the app is being run on and adjust these calculations accordingly?

Thanks

On Aug 3, 4:52 pm, TreKing treking...@gmail.com wrote:
 On Tue, Aug 3, 2010 at 4:05 AM, Horace Bell-Gam horaceb1...@gmail.comwrote:

  No, so far all I've been able to do is overlay an image of the target and
  make the entire object respond to a click.

 You know:
 - The center of the image
 - The length of each band
 - Where the user clicks on the image (via onTouchEvents, me thinks)
 - Simple algebra to calculate the distance of a point from the center of the
 image (I hope)

 That's all you should need to figure out which band the user has touched.

 What have you tried thus far? Where are you stuck?

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Programming a target in an Android Application

2010-08-03 Thread kingh32
Thanks, both of you for your help.
I imagine I'll be back with more questions soon!

On Aug 3, 8:08 pm, Bob Kerns r...@acm.org wrote:
 Everything -- both the positions and the image widget size -- will be
 in pixel coordinates. Actually, you don't need to know that -- just
 that they're the same. Hell, I could even be wrong; I'm not going to
 take out a microscope and check.

 If you have different coordinates for your image data (or even if you
 don't or don't know or might want to scale in the future or are
 paranoid), simply scale by the ratio of the image data : image widget.
 A scale factor of 1:1 won't cause you any trouble.

 There are times to be absolute, and times to be relative. This is one
 of the latter.

 On Aug 3, 9:25 am, kingh32 horaceb1...@gmail.com wrote:



  Hello - Thanks for your reply!

  What you have just mentioned is pretty much where I'm stuck!
  I don't know how to identify programatically where the target actually
  is. Would this be done using pixel coordinates?
  Is there a way to determine the resolution of the phone (screen) that
  the app is being run on and adjust these calculations accordingly?

  Thanks

  On Aug 3, 4:52 pm, TreKing treking...@gmail.com wrote:

   On Tue, Aug 3, 2010 at 4:05 AM, Horace Bell-Gam 
   horaceb1...@gmail.comwrote:

No, so far all I've been able to do is overlay an image of the target 
and
make the entire object respond to a click.

   You know:
   - The center of the image
   - The length of each band
   - Where the user clicks on the image (via onTouchEvents, me thinks)
   - Simple algebra to calculate the distance of a point from the center of 
   the
   image (I hope)

   That's all you should need to figure out which band the user has touched.

   What have you tried thus far? Where are you stuck?

   ---
--
   TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
   transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Programming a target in an Android Application

2010-08-02 Thread kingh32
Hello

I'm currently trying to program a target as part of an Android
Application.
I want the user to be able to touch a particular band within the
target with the app being able to acknowledge the area selected i.e.
coordinates and put that data into a database.

Does anyone have any suggestions as to how I can make an image of a
target function in this way?

The target is made up of 6-9 bands, each being the same width.

Thanks

Kingh32

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en