Silvio Pereira Silvio Pereira - 5 months ago 13
Android Question

Click in number textbox and call that number

I want to on click number in text box call the number, i knew i need to put my text box clickable its already done, and i need to do a code to put onclick do some stuff but i need help in that part.

This is my xml for dat java class:

<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Telefone/Fax : 244892501"
android:id="@+id/textView8"
android:textSize="20dp"
android:layout_below="@+id/textView7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_weight="1"
android:clickable="true" />


This is my java class

private static Button button1;

ImageView ivImageFromUrl;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
ivImageFromUrl = (ImageView) findViewById(R.id.iv_image_from_url);

Picasso.with(getApplicationContext()).load("http://i67.tinypic.com/20k9n42.jpg").into(ivImageFromUrl);

button1 = (Button)findViewById(R.id.button1);

button1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent NameOfTheIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.docdroid.net/Vh3yPiJ/contatos-lubrifuel.pdf.html"));
startActivity(NameOfTheIntent);
}


})
;}


}

Answer

Simply do this:

TextView numTextView = (TextView) findViewById(R.id.textView8);
numTextView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel: 244892501"));
    context.startActivity(intent);
}

And of course, add this to your manifest:

<uses-permission android:name="android.permission.CALL_PHONE" />
Comments