Re: [android-developers] Problems with ViewGroup.addView()

2010-03-26 Thread Liviu Ungureanu
"Why doesn't the "Ori" text shows up?"

Because:
   TextView t = new TextView(this);
   t.setText("Ori");
   TextView t2 = new TextView(this);
   t.setText("Ori2");   // here you reset the text from TextView t
instead of TextView t2.
  // TextView t2 is empty: you don't set any
text

   LinearLayout layout = (LinearLayout)
findViewById(R.id.mainLayout);
   layout.addView(t);
   layout.addView(t2);

As hint: Try to set LayoutParams for your TextView before adding it to
layout

-- 
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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.


Re: [android-developers] Checking if a cursor contains a valid result

2010-04-14 Thread Liviu Ungureanu
You can try cursor.getCount() before cursor.moveToFirst().
>From javaDoc:
public abstract int getCount ()
Since: API Level 1 <../../../guide/appendix/api-levels.html#level1>

Returns the numbers of rows in the cursor.
 Returns

   - the number of rows in the cursor.

If getCount() is 0 that mean your cursor is empty.

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

To unsubscribe, reply using "remove me" as the subject.


Re: [android-developers] How to bring activity to front?

2010-04-14 Thread Liviu Ungureanu
I think you cannot bring an activity to front after the activity called his
onPause() method without actions from user(start your application from menu,
from notification, resume it)  or without starting it from an service.

Maybe someone else know more but if you want to bring your activity to front
try to start it from an service if your application need one or notify the
user via notification and set the pending intent to start your activity.

-- 
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

To unsubscribe, reply using "remove me" as the subject.


Re: [android-developers] Google Search

2010-04-14 Thread Liviu Ungureanu
Hi!

First, Google Local Search return the results in JSON format.
This is an example link :
http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=Restaurant,%20loc:%2047.3,8.6&hl=en&rsz=large&start=1

I create my url using latitude and longitude got from GPS like this:
String url = "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=";
+ what + ",%20loc:%20" + lat +"," + lng + "&hl=en&rsz=large&start=" +
offset;

here is my JSON Parser class:

package com.liviu.app.nearbyplace.data;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.liviu.app.nearbyplace.util.Util;

public class JSONParser {
 // data
private String TAG = "JSONParser";
private ArrayList items;
private ItemFound itemFound;
 public JSONParser() {
items = new ArrayList();
}
 public boolean parse(String source){
String result  = Util.getFile(source);
if(result.length() < 1)
return false;
Log.e(TAG, "parse " + result);
items.clear();
 try {
JSONObject json = new JSONObject(result);
JSONObject jsec = json.getJSONObject("responseData");
JSONArray jResults = jsec.getJSONArray("results");
jResults.toString();
for(int i = 0; i < jResults.length(); i++){
JSONObject jObj = jResults.getJSONObject(i);
itemFound = new ItemFound();
itemFound.setTitle(jObj.getString("title"));
itemFound.setCity(jObj.getString("city"));
itemFound.setCountry(jObj.getString("country"));
itemFound.setContent(jObj.getString("content"));
 JSONArray phoneObj = jObj.getJSONArray("phoneNumbers");
for(int j = 0; j < phoneObj.length(); j++){
JSONObject jPhoneObj = phoneObj.getJSONObject(j);
if(jPhoneObj.getString("type").length() < 1)
itemFound.setPhone(jPhoneObj.getString("number"));
else if(jPhoneObj.getString("type").equals("Fax"))
itemFound.setFax(jPhoneObj.getString("number"));
}
itemFound.setLatitude(jObj.getString("lat"));
itemFound.setLongitude(jObj.getString("lng"));
itemFound.setStreet(jObj.getString("streetAddress"));
Log.e(TAG, "ItemFound: " + itemFound.toString());
items.add(itemFound);
}
 Log.e(TAG, "parse() finished with " + items.size() + " items found!");
}
catch (JSONException e) {
e.printStackTrace();
return false;
}
 return true;
}
 public ArrayList getItemsFound() {
return items;
}

}


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

To unsubscribe, reply using "remove me" as the subject.


Re: [android-developers] Need Help--- Regarding Creating Database and Tables

2010-04-19 Thread Liviu Ungureanu
Hi!

 I use this method to work with database:

 // this is my DatabaseManager class

package com.liviu.app.nearbyplace.data;

import java.util.ArrayList;

import com.liviu.app.nearbyplace.util.Constants;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;


public class DatabaseManager {
 //data
private String  TAG = "DatabaseManager";
private SQLiteDatabase db;
private Context context;
public DatabaseManager(Context ctx) {
 Log.e(TAG, "DatabaseManager Constructor");
context = ctx;
 openAndCreateDatabase();
closeDatabaseManager();
}
 public boolean openAndCreateDatabase(){
try{
 db = context.openOrCreateDatabase(Constants.DATABASE_NAME,
Context.MODE_PRIVATE, null);
Log.e(TAG,"Database is ready!");

// here I create my tables:
db.execSQL(Constants.CREATE_SAVED_ITEMS_TABLE);
db.execSQL(Constants.CREATE_HISTORY_TABLE);
 return true;
}
catch (SQLException e){
Log.e(TAG,"ERROR at accesing database!");
Log.e(TAG,e.toString());
return false;
}
catch (IllegalStateException e) {
e.printStackTrace();
Log.e(TAG, "database is not closed in openAndCreateDatabase()");
closeDatabaseManager();
return false;
}
}
 public boolean openDatabase(){
 if(db != null && db.isOpen())
db.close();
try{
db =
context.openOrCreateDatabase(Constants.DATABASE_NAME,Context.MODE_PRIVATE,
null);
return true;
}
catch (SQLException e){
Log.e(TAG,"ERROR at accesing database!");
Log.e(TAG,e.toString());
return false;
}
catch (IllegalStateException e) {
e.printStackTrace();
Log.e(TAG, "database is not closed in openDatabase()");
closeDatabaseManager();
return openDatabase();
}
 }
 public void closeDatabaseManager(){
 if(db.isOpen())
db.close();
else
Log.e(TAG,"Database is not open!");
}

public boolean insertToHistory(String when, String what, int count) {
ContentValues values = new ContentValues(3);
 values.put(Constants.DATE_FIELD, when);
values.put(Constants.ITEM_TITLE_FIELD, what);
values.put(Constants.ITEM_RESULTS_COUNT_FIELD, count);
 long affectedRows = 0;
try{
affectedRows = db.insertOrThrow(Constants.TABLE_HISTORY, null, values);
Log.e(TAG, "affectedRows: " + affectedRows);
if(affectedRows != -1)
return true;
else
return false;
}
catch (SQLException e) {
Log.e(TAG, "nu am inserat in baza de date " + what + " count: " + count);
e.printStackTrace();
return false;
}
}

public ArrayList getSuggestions() {
Log.e(TAG, "getSuggestions()");
HistoryItem hItem;
ArrayList  suggestions;
String[] sProjection = new String[]{"distinct " +
Constants.ITEM_TITLE_FIELD, Constants.ITEM_RESULTS_COUNT_FIELD};
Cursor   cSuggestions   = db.query(Constants.TABLE_HISTORY,
  sProjection,
  null,
  null,
  null,
  null,
  null);
if(cSuggestions == null){
Log.e(TAG, "cSuggestions is null");
return null;
}
 int numRows = cSuggestions.getCount();
suggestions = new ArrayList(numRows);
cSuggestions.moveToFirst();
 for(int i = 0; i < numRows; i++){
hItem = new HistoryItem(cSuggestions.getString(0), cSuggestions.getInt(1));
suggestions.add(hItem);
Log.e(TAG, "Suggestion: " + cSuggestions.getString(0) + " results count: " +
cSuggestions.getInt(1));
cSuggestions.moveToNext();
}
 Log.e(TAG, "suggestions count: " + suggestions.size());
return suggestions;
}
 public String[] getSuggestionsAsArray() {
Log.e(TAG, "getSuggestions()");
String[]  suggestions;
String[] sProjection = new String[]{ "distinct " +
Constants.ITEM_TITLE_FIELD, Constants.ITEM_RESULTS_COUNT_FIELD };
Cursor   cSuggestions   = db.query(Constants.TABLE_HISTORY,
  sProjection,
  null,
  null,
  null,
  null,
  null);
if(cSuggestions == null){
Log.e(TAG, "cSuggestions is null");
return null;
}
 int numRows = cSuggestions.getCount();
suggestions = new String[numRows];
cSuggestions.moveToFirst();
 for(int i = 0; i < numRows; i++){
suggestions[i] = cSuggestions.getString(0);
Log.e(TAG, "Suggestion: " + cSuggestions.getString(0) + " results count: " +
cSuggestions.getInt(1));
cSuggestions.moveToNext();
}
 Log.e(TAG, "suggestions count: " + suggestions.length);
return suggestions;
}

public ArrayList getHistoryDates() {
ArrayList datesList;
int   numRows;
String[]   datesProjection= new String[]{ "distinct " +
Constants.DATE_FIELD };
Cursor   dateCursor = db.query(Constants.TABLE_HISTORY,
datesProjection,
null,
null,
null,
null,
null);
if(dateCursor == null){
Log.e(TAG, "dateCursor is null");
return new ArrayList();
}
numRows = dateCursor.getCount();
datesList = new ArrayList(numRows);
 dateCursor.moveToFirst();
 for(int i = 0; i < numRows; i++){
Log.e(TAG, "date: " + dateCursor.getString(0));
datesList.add(dateCursor.getString(0));
dateCursor.moveToNext();
}
 Log.e(TAG, "getHistoryDates() return " + datesList.size() + " dates");
 return datesList;
}

public ArrayList getHistoryForDate(String date) {
ArrayList hItemsList;
int numRows;
String[] hItemsProjection = new String[] { Constants.ITEM_TITLE_FIELD,
Constan

[android-developers] How can I remove an item from ExpandableListView or how can I reload an single group from ExpandableListView?

2010-04-20 Thread Liviu Ungureanu
Hi!

I have a ExpandableListView in my application. I want to remove an item from
an group but I can't get a solution.
As adapter I use an standard SimpleExpandableListAdapter.

Until now, I managed to remove just data from an item but the view still
remain in adapter:

 ((Map)adapter.getChild(groupPositionOnClick,
childPositionOnClick)).remove("historyItem");
 adapter.notifyDataSetChanged();
 adapter.notifyDataSetInvalidated();

An other option is to reload all adapter but is not so efficient.

Thank you!

-- 
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

Re: [android-developers] Icons for submenu items doesn't show up

2010-04-20 Thread Liviu Ungureanu
Try to use PopUpWindow
class.
Here you have an
example
.

-- 
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

Re: [android-developers] AlertDialog Timeout

2010-04-22 Thread Liviu Ungureanu
Hi!

 You have to create a thread which count until 3 and when counter is 3 you
have to call - via an handler -  yourDialogObject.cancel().

Hope this help.

-- 
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

Re: [android-developers] Display routes dynamically on Map Application

2010-04-22 Thread Liviu Ungureanu
Do you know you can do that using intents and Maps Application? So what you
want to do: implement a new way to get directions to an some GeoPoint inside
of your applications or just use Maps? Last method is a lot  easier...

2010/4/22 ~ TreKing 

> On Thu, Apr 22, 2010 at 1:05 AM, SREEHARI <
> sreehari.madhusooda...@wipro.com> wrote:
>
>> Should I use the graph data structure concepts using some algorithms?
>>
>
> What graph data structure concepts?
>
>
> -
> TreKing - Chicago transit tracking app for Android-powered devices
> http://sites.google.com/site/rezmobileapps/treking
>
> --
> 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
>

-- 
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

Re: [android-developers] Need Help--- Regarding Creating Database and Tables

2010-04-28 Thread Liviu Ungureanu
Hi! I'm happy to see this solution helped you.

For question 1:
 "before even the app is launched" I'm not sure if this is possible. To get
access to a database you need an context: you can get context just from
activities, services...You can try to do something like this: When your
application start for the first time, populate your tables with informations
from sdcard. Do not forget to show to user an progress dialog with some
informations about populating process.

For question 2.
 I you refer here to unicode strings, I do know if this is possible or not.
You have to try :).

Thank you!


2010/4/28 amsale zelalem 

> thank you so  much for the posted solution. it is of great help for me.
> I want to ask you though some more questions.
> 1.  I would like to populate my tables statically(before even the app is
> launched) may be reading from a file onto the db. How can I do it?
> 2. I would like to add texts written in languages different from english.
> How can I do this too?
> Please I am really in need of these two things and quick response would be
> appreciated.
> thank you in advance
>
> --- On *Mon, 4/19/10, Liviu Ungureanu * wrote:
>
>
> From: Liviu Ungureanu 
> Subject: Re: [android-developers] Need Help--- Regarding Creating Database
> and Tables
> To: android-developers@googlegroups.com
> Date: Monday, April 19, 2010, 12:42 PM
>
> Hi!
>
>  I use this method to work with database:
>
>  // this is my DatabaseManager class
>
>  package com.liviu.app.nearbyplace.data;
>
> import java.util.ArrayList;
>
> import com.liviu.app.nearbyplace.util.Constants;
>
> import android.content.ContentValues;
> import android.content.Context;
> import android.database.Cursor;
> import android.database.SQLException;
> import android.database.sqlite.SQLiteDatabase;
> import android.util.Log;
>
>
> public class DatabaseManager {
>  //data
> private String TAG = "DatabaseManager";
> private SQLiteDatabase db;
> private Context context;
>  public DatabaseManager(Context ctx) {
>  Log.e(TAG, "DatabaseManager Constructor");
> context = ctx;
>  openAndCreateDatabase();
> closeDatabaseManager();
> }
>  public boolean openAndCreateDatabase(){
> try{
>  db = context.openOrCreateDatabase(Constants.DATABASE_NAME,
> Context.MODE_PRIVATE, null);
> Log.e(TAG,"Database is ready!");
>
> // here I create my tables:
> db.execSQL(Constants.CREATE_SAVED_ITEMS_TABLE);
> db.execSQL(Constants.CREATE_HISTORY_TABLE);
>  return true;
> }
> catch (SQLException e){
> Log.e(TAG,"ERROR at accesing database!");
> Log.e(TAG,e.toString());
> return false;
> }
> catch (IllegalStateException e) {
> e.printStackTrace();
> Log.e(TAG, "database is not closed in openAndCreateDatabase()");
> closeDatabaseManager();
> return false;
> }
> }
>  public boolean openDatabase(){
>  if(db != null && db.isOpen())
> db.close();
> try{
> db =
> context.openOrCreateDatabase(Constants.DATABASE_NAME,Context.MODE_PRIVATE,
> null);
> return true;
> }
> catch (SQLException e){
> Log.e(TAG,"ERROR at accesing database!");
> Log.e(TAG,e.toString());
> return false;
> }
> catch (IllegalStateException e) {
> e.printStackTrace();
> Log.e(TAG, "database is not closed in openDatabase()");
> closeDatabaseManager();
> return openDatabase();
> }
>  }
>  public void closeDatabaseManager(){
>  if(db.isOpen())
> db.close();
> else
> Log.e(TAG,"Database is not open!");
> }
>
> public boolean insertToHistory(String when, String what, int count) {
> ContentValues values = new ContentValues(3);
>  values.put(Constants.DATE_FIELD, when);
> values.put(Constants.ITEM_TITLE_FIELD, what);
> values.put(Constants.ITEM_RESULTS_COUNT_FIELD, count);
>  long affectedRows = 0;
> try{
> affectedRows = db.insertOrThrow(Constants.TABLE_HISTORY, null, values);
> Log.e(TAG, "affectedRows: " + affectedRows);
> if(affectedRows != -1)
> return true;
> else
> return false;
> }
> catch (SQLException e) {
> Log.e(TAG, "nu am inserat in baza de date " + what + " count: " + count);
> e.printStackTrace();
> return false;
> }
> }
>
> public ArrayList getSuggestions() {
> Log.e(TAG, "getSuggestions()");
> HistoryItem hItem;
> ArrayList  suggestions;
> String[] sProjection = new String[]{"distinct " +
> Constants.ITEM_TITLE_FIELD, Constants.ITEM_RESULTS_COUNT_FIELD};
> Cursor   cSuggestions   = db.query(Constants.TABLE_HISTORY,
>  sProjection,
>  null,
>  null,
>  null,
>  null,
>  null);
> if(cSuggestions == null){
> Log.e(TAG, &quo