android - Place a call from a View -


i have app consisting of activity displays custom view created (a dialpad). custom view has dials, edittext used display number entered , phonebutton want use place call number user has entered. im trying write listener button. listener must take number edittext , place call it.

ive found code can used place calls , placed in activity:

public void call(string number){     try {         intent callintent = new intent(intent.action_call);         callintent.setdata(uri.parse(number));         startactivity(callintent);         } catch (exception e) {         // todo auto-generated catch block         e.printstacktrace();         } } 

but listener button inside custom view class. how can call call() method inside activity button listener in view class?

***edit**

it seems there easier way of doing it, found code insert view class:

public void call(string number){         intent intent = new intent(intent.action_call);         string dialnumber = "tel:";         dialnumber = dialnumber + number;         intent.setdata(uri.parse(dialnumber));         getcontext().startactivity(intent);     } 

calling method listener places call.

not idea call activity within view if you're doing through startactivity. problem view should portable activity want create. making direct calls or startactivity you're coupling single use. you'll never able reuse anywhere right there, plus using startactivity() isn't going think do.

instead i'd create interface , add method view allows activity register listener dialing number. example:

public interface diallistener {    public void ondialed( string number ); } ... public class someactivity extends activity implements diallistener {     public void oncreate( ... ) {         yourcustomdialer dialer = (yourcustomerdialer)findviewbyid( r.id.dialer );         dialer.setdiallistener( );     }      public void ondialed( string number ) {         // here dialed number     } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -