Reputation: 73
I have dialog contain TextView. Inside the TextView I have number so i want to set onClick method for the TextView and I want to use call method to call the number inside the TextView
Inside the dialog xml file i set the textview as below
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#2d76ba"
android:layout_toRightOf="@+id/image"
android:onClick="no1"
android:clickable="true"/>
and here is my dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.pop); // pop is my dialog xml
dialog.setTitle("Phone Call");
TextView text = (TextView) dialog.findViewById(R.id.text1);
text.setText(values[0]); /// I'm calling the number from array
public void no1(View v)
{
Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:"+values[0]));
startActivity(dial);
}
but the onClick method (no1) is wrong it says "void is an invalid type for the variable no1"
how can i correct the method to work inside the dialog ? I tried to make it outside the dialog but when i click the textview the logcat says
11-04 13:39:48.666: E/AndroidRuntime(26249): java.lang.IllegalStateException: Could not find a method no1(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.TextView with id 'text1'
so it looks like the function is not available
Upvotes: 1
Views: 1177
Reputation: 3339
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.pop); // pop is my dialog xml
dialog.setTitle("Phone Call");
TextView text = (TextView) dialog.findViewById(R.id.text1);
text.setText(values[0]);
text.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:"+Global.values[0]));
startActivity(dial);
}
});
Upvotes: 2