Is it possible to connect a Windows Azure database to an Android ListBox? I 
have an app that needs to pull live scores off of a database. I have Azure SQL 
Server already set up, but what would be the easiest way to connect Android to 
that or a different server?
Nick

From: 葛维维 
Sent: Wednesday, August 17, 2011 2:47 AM
To: [email protected] 
Subject: Re: [android-discuss] Database and ListView

U should use like this: 
......................

Cursor cursor = (Cursor)this.getListAdapter().getItem(position);

String t = cursor.getString(cursor.getColumnIndex('xxx'));
...................


2011/8/17 kirti waykole <[email protected]>

  hello friends,

  I am displaying data from database in listview. when i select any
  row, that row detail should display into toast or into Dialog box .
  Here i am using Toast. But instead of displaying the names it shows
  android.SQLite@4376f048.

  Please help me how i solve this problem

  this is my main Activity:


  package org.kah;

  import android.app.AlertDialog;
  import android.app.Dialog;
  import android.app.ListActivity;
  import android.content.ContentValues;
  import android.content.DialogInterface;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.Bundle;
  import android.provider.BaseColumns;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.CursorAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  import android.widget.Toast;


  public class SQLiteDemo extends ListActivity
  {
         private static final int DIALOG_ID = 100;

         private SQLiteDatabase database;

         private CursorAdapter dataSource;

         private View entryView;

         private EditText firstNameEditor;

         private EditText lastNameEditor;

         private static final String fields[] = { "first", "last", 
BaseColumns._ID };

         /** Called when the activity is first created. */
         @Override
         public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                 DatabaseHelper helper = new DatabaseHelper(this);
                 database = helper.getWritableDatabase();
                 Cursor data = database.query("names", fields, null, null, 
null, null,
                                 null);

                 dataSource = new SimpleCursorAdapter(this, R.layout.row, data, 
fields,
                                 new int[] { R.id.first, R.id.last });

                 ListView view = getListView();
                 view.setHeaderDividersEnabled(true);
                 view.addHeaderView(getLayoutInflater().inflate(R.layout.row, 
null));

                 setListAdapter(dataSource);
         }

         @Override
         public boolean onCreateOptionsMenu(Menu menu) {
                 menu.add(0, DIALOG_ID, 1, R.string.addItem);
                 return true;
         }

         @Override
         protected void onListItemClick(ListView l, View v, int position, long 
id) {
                 super.onListItemClick(l, v, position, id);
                 // Get the item that was clicked
                 Object o = this.getListAdapter().getItem(position);
                 String keyword = o.toString();
                 Toast.makeText(this, "You selected: " + keyword, 
Toast.LENGTH_LONG)
                                 .show();
         }

         @Override
         public boolean onMenuItemSelected(int featureId, MenuItem item) {
                 if (item.getItemId() == DIALOG_ID) {
                         showDialog(DIALOG_ID);
                 }
                 return true;
         }

         @Override
         protected Dialog onCreateDialog(int id)
         {
                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
                 entryView = getLayoutInflater().inflate(R.layout.entry, null);
                 builder.setView(entryView);
                 firstNameEditor = (EditText) 
entryView.findViewById(R.id.firstName);
                 lastNameEditor = (EditText) 
entryView.findViewById(R.id.lastName);
                 builder.setTitle(R.string.addDialogTitle);
                 builder.setPositiveButton(R.string.addItem,
                                 new DialogInterface.OnClickListener() {

                                         @Override
                                         public void onClick(DialogInterface 
dialog, int which) {
                                                 dialog.dismiss();
                                                 ContentValues values = new 
ContentValues();
                                                 values.put("first", 
firstNameEditor.getText()
                                                                 .toString());
                                                 values.put("last", 
lastNameEditor.getText().toString());
                                                 database.insert("names", null, 
values);
                                                 
dataSource.getCursor().requery();
                                         }
                                 });

                 builder.setNegativeButton(R.string.cancelItem,
                                 new DialogInterface.OnClickListener()
                                         {

                                         @Override
                                         public void onClick(DialogInterface 
dialog, int which) {
                                                 dialog.cancel();
                                         }
                                 });
                 return builder.create();
         }
  }

  --
  You received this message because you are subscribed to the Google Groups 
"Android Discuss" group.
  To post to this group, send email to [email protected].
  To unsubscribe from this group, send email to 
mailto:android-discuss%[email protected].
  For more options, visit this group at 
http://groups.google.com/group/android-discuss?hl=en.






-- 
Best regards.

-- 
You received this message because you are subscribed to the Google Groups 
"Android Discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/android-discuss?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Android Discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/android-discuss?hl=en.

Reply via email to