<分区>
我有一个包含 TextView 的对话框。在 TextView 中我有数字,所以我想为 TextView 设置 onClick 方法,我想使用 call 方法调用 TextView 中的数字
在对话框 xml 文件中,我将 TextView 设置如下
<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"/>
这是我的对话
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);
}
但是 onClick 方法 (no1) 是错误的,它说“void 是变量 no1 的无效类型”
如何更正对话框中的工作方法? 我试图将其置于对话框之外,但是当我单击 textview 时,logcat 显示
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'
所以看起来功能不可用