Android 在机箱对话框界面内添加一个开关机箱。按钮\u正
在我的android应用程序中,每个数字的线性布局中有一个不同数字的Activity。每个线性布局都有一个onClick方法,该方法调用活动中的一个方法,以在调用号码之前显示一个对话框,如果选择了按钮YES,则会启动一个intent action_调用 这是我的xml文件:Android 在机箱对话框界面内添加一个开关机箱。按钮\u正,android,onclick,onclicklistener,Android,Onclick,Onclicklistener,在我的android应用程序中,每个数字的线性布局中有一个不同数字的Activity。每个线性布局都有一个onClick方法,该方法调用活动中的一个方法,以在调用号码之前显示一个对话框,如果选择了按钮YES,则会启动一个intent action_调用 这是我的xml文件: ... <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" androi
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:onClick="onClick"
android:id="@+id/ln_u">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ps_u"
android:src="@mipmap/ic_call"
android:background="@android:color/transparent"
android:layout_marginLeft="12dp"
/>
<TextView
android:id="@+id/nu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:text="123456"
android:textSize="17sp"
android:layout_marginTop="5dp"
android:layout_marginLeft="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:onClick="onClick"
android:id="@+id/ln_r">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ps_r"
android:src="@mipmap/ic_call"
android:background="@android:color/transparent"
android:layout_marginLeft="12dp"
/>
<TextView
android:id="@+id/nu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:text="123456"
android:textSize="17sp"
android:layout_marginTop="5dp"
android:layout_marginLeft="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:onClick="onClick"
android:id="@+id/ln_t">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ps_t"
android:src="@mipmap/ic_call"
android:background="@android:color/transparent"
android:layout_marginLeft="12dp"
/>
<TextView
android:id="@+id/nu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:text="123456"
android:textSize="17sp"
android:layout_marginTop="5dp"
android:layout_marginLeft="16dp" />
</LinearLayout>
...
我想要实现的是在case DialogInterface中添加另一个Switch/case方法的可能性。BUTTON_肯定:它获取不同线性布局的id,并且对于每个id,使用意向调用动作调用相对号码
希望有人能帮助我。
提前谢谢
Brus我还没有机会对此进行测试,但是为什么不使用一个静态方法来获得这样的AlertDialog:
public static AlertDialog getCallPhoneAlertDialog(final Context context, final String phoneNumber) {
return new AlertDialog.Builder(context)
.setTitle("CALL")
.setMessage("CALL THE NUMBER? " + phoneNumber)
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Uri call = Uri.parse("tel:" + phoneNumber);
Intent intent = new Intent(Intent.ACTION_CALL, call);
context.startActivity(intent);
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).create();
}
嗨,谢谢你的回复。在这种方法中,我将错过一个视图,并在使用它时出错。当然,我在我的日志中得到了这一点:java.lang.IllegalStateException:在视图类android.widget.LinearLayout上的onClick处理程序的活动类com.brusasu.ursula55.ActivityFrontOsocorso中找不到onClick view的方法,id为“ln_u u”从外部类调用它并传入上下文和电话号码。无需活动来实现DialogInterface.OnClickListener
public static AlertDialog getCallPhoneAlertDialog(final Context context, final String phoneNumber) {
return new AlertDialog.Builder(context)
.setTitle("CALL")
.setMessage("CALL THE NUMBER? " + phoneNumber)
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Uri call = Uri.parse("tel:" + phoneNumber);
Intent intent = new Intent(Intent.ACTION_CALL, call);
context.startActivity(intent);
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).create();
}