Search Results

Search found 5 results on 1 pages for 'urobo'.

Page 1/1 | 1 

  • how to read user input from custom dialog in android?

    - by urobo
    I'd like to use a custom dialog built over an AlterDialog to obtain login info from the user. In this manner I first use the layoutinflater to get the layout and then put it in the AlertDialog.Builder.setView() method. LayoutInflater inflater = (LayoutInflater) Home.this.getSystemService(LAYOUT_INFLATER_SERVICE); layoutLogin = inflater.inflate(R.layout.login,(ViewGroup) findViewById(R.id.rl)); My layout consists of two textview and two editext for username and password respectively. Then I override the onCreateDialog method, checking the dialog id and putting all together, during the building phase I use the setButton(...) method to add a confirmation Button, neutral though: /* (non-Javadoc) * @see android.app.Activity#onCreateDialog(int) */ @Override protected Dialog onCreateDialog(int id) { AlertDialog d = null; AlertDialog.Builder builder = new AlertDialog.Builder(this); switch(id){ ... case Home.DIALOG_LOGIN: builder.setView(layoutLogin); builder.setMessage("Sign in to your DyCaPo Account").setCancelable(false); d=builder.create(); d.setTitle("Login"); Message msg = new Message(); msg.setTarget(Home.this.handleLogin); d.setButton(Dialog.BUTTON_NEUTRAL,"Sign in",msg); break; ... } return d; } Then I setup the Handler handleLogin: private Handler handleLogin= new Handler(){ /* (non-Javadoc) * @see android.os.Handler#handleMessage(android.os.Message) */ @Override public void handleMessage(Message msg) { String input = usernameInput.getText().toString(); //this should hold the EditText field for the username } }; which is just a stub up to now. what I don't get is when and where I have to access the two fields since I tried to save a reference to them but unfortunately I always get a null pointer exception. Can anyone tell me what I do wrong and give some guidelines to work with custom dialogs. Thanks in advance! :)

    Read the article

  • read user Input of custom dialogs

    - by urobo
    I built a custom dialog starting from an AlertDialog to obtain login information from a user. So the dialog contains two EditText fields, using the layoutinflater service I obtain the layout and I'm saving a reference to the fields. LayoutInflater inflater = (LayoutInflater) Home.this.getSystemService(LAYOUT_INFLATER_SERVICE); layoutLogin = inflater.inflate(R.layout.login,(ViewGroup) findViewById(R.id.rl)); usernameInput =((EditText)findViewById(R.id.getNewUsername)); passwordInput = ((EditText)findViewById(R.id.getNewPassword)); Then I have my overridden onCreateDialog(...) : { AlertDialog d = null; AlertDialog.Builder builder = new AlertDialog.Builder(this); switch(id){ ... case Home.DIALOG_LOGIN: builder.setView(layoutLogin); builder.setMessage("Sign in to your DyCaPo Account").setCancelable(false); d=builder.create(); d.setTitle("Login"); Message msg = new Message(); msg.setTarget(Home.this.handleLogin); Bundle data = new Bundle(); data.putString("username", usernameInput.getText().toString());// <---null pointer Exception data.putString("password", passwordInput.getText().toString()); msg.setData(data); d.setButton(Dialog.BUTTON_NEUTRAL,"Sign in",msg); break; ... return d; } and the handler set in the Message: private Handler handleLogin= new Handler(){ /* (non-Javadoc) * @see android.os.Handler#handleMessage(android.os.Message) */ @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub Log.d("Message Received", msg.getData().getString("username")+ msg.getData().getString("password")); } }; which for now works as a debugging tool. That's all. The Question is: what am I doing wrong? Because when I reach the line highlighted in the code ( the line in which I read the fields in the dialog ) I always get a null pointer exception. Could somebody please tell me the reason why it is so? And give some guidelines to work with dialogs. Thanks in advance!

    Read the article

  • why Geocoder.getFromLocationName(...) returns an empty list?

    - by urobo
    I'm using the android.location.Geocoder for the first time. The Idea is: I have a Listener on a button which takes input from an EditText and resolve the location. Up to now it's debugging phase, so I have no handler taking messages from the thread, only geocoding and write to logcat. Q: Why this method always returns an empty list of Address objects? private View.OnClickListener checkLocation = new View.OnClickListener() { @Override public void onClick(View v) { location = ((EditText)findViewById(R.id.getLocation)).getText().toString(); Thread thr = new Thread(){ public void run (){ Log.d("Looking for", location); Geocoder gc = new Geocoder(ctx,Locale.ITALY); try { fa= gc.getFromLocationName(location, 3); if (fa.isEmpty())Log.d("getFromLocationName", "NothingFound"); else { int size= fa.size(); for (int i = 0; i<size ;i++) Log.d("getFromLocationName.at("+ String.valueOf(i) +")", fa.get(i).getAddressLine(0)+", "+fa.get(0).getAddressLine(1)); } } catch (IOException e) { Log.e("IOException", e.getMessage()); } } }; thr.start(); } }; manifest: <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> Somebody knows why? (btw I am using 1.6 sdk) Input tried

    Read the article

  • android get duration from maps.google.com directions

    - by urobo
    At the moment I am using this code to inquire google maps for directions from an address to another one, then I simply draw it on a mapview from its GeometryCollection. But yet this isn't enough I need also to extract the total expected duration from the kml. can someone give a little sample code to help me? thanks StringBuilder urlString = new StringBuilder(); urlString.append("http://maps.google.com/maps?f=d&hl=en"); urlString.append("&saddr=");//from urlString.append( Double.toString((double)src.getLatitudeE6()/1.0E6 )); urlString.append(","); urlString.append( Double.toString((double)src.getLongitudeE6()/1.0E6 )); urlString.append("&daddr=");//to urlString.append( Double.toString((double)dest.getLatitudeE6()/1.0E6 )); urlString.append(","); urlString.append( Double.toString((double)dest.getLongitudeE6()/1.0E6 )); urlString.append("&ie=UTF8&0&om=0&output=kml"); //Log.d("xxx","URL="+urlString.toString()); // get the kml (XML) doc. And parse it to get the coordinates(direction route). Document doc = null; HttpURLConnection urlConnection= null; URL url = null; try { url = new URL(urlString.toString()); urlConnection=(HttpURLConnection)url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.connect(); dbf = DocumentBuilderFactory.newInstance(); db = dbf.newDocumentBuilder(); doc = db.parse(urlConnection.getInputStream()); if(doc.getElementsByTagName("GeometryCollection").getLength()>0) { //String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getNodeName(); String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getFirstChild().getNodeValue() ; //Log.d("xxx","path="+ path); String[] pairs = path.split(" "); String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude lngLat[1]=latitude lngLat[2]=height // src GeoPoint startGP = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6)); mMapView01.getOverlays().add(new MyOverLay(startGP,startGP,1)); GeoPoint gp1; GeoPoint gp2 = startGP; for(int i=1;i<pairs.length;i++) // the last one would be crash { lngLat = pairs[i].split(","); gp1 = gp2; // watch out! For GeoPoint, first:latitude, second:longitude gp2 = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6)); mMapView01.getOverlays().add(new MyOverLay(gp1,gp2,2,color)); //Log.d("xxx","pair:" + pairs[i]); } mMapView01.getOverlays().add(new MyOverLay(dest,dest, 3)); // use the default color } }catch (MalformedURLException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); }catch (SAXException e){ e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } }

    Read the article

  • android use local service to refresh map UI

    - by urobo
    I don't need a strict code related answer I just need somebody to tell me what I am missing. My application has to retrieve from a web service (xmlrpc) the positions of some users I know and update their position on a MapView. So I decided to use a Service and an Activity extending MapActivity to show results. I thought about two solutions: I ) start the service and make it ask every minute for these positions and send them to the activity as a bundle via intent. (This didn't work out well, since once shown I couldn't find a method to let the activity continue refresh itself until she stop receiving intents+data from the service) II ) Incorporate a thread within the activity which starts the service via context.startService(...) every minute. And the MapUI refresh itself once the service send back an intent and stop itself. (Maybe I will fall in the same problem category as before I haven't tryied yet). I am also giving directions (via maps.google ws) in this way I'd like to refresh only users positions on the map and save the route. What Am I missing do you have any suggestions? related to activities/services internal mechanics, don't know launch modes, use broadcast receivers or intent filters? Thanks in advance

    Read the article

1