Android 表现出警觉而不是敬酒
正如您从下面的代码中看到的,我有一个if和else语句,其中if是if,它将显示一个祝酒词。现在我想要的是,我希望显示一个包含一些文本和Ok按钮的警报,而不是显示toastAndroid 表现出警觉而不是敬酒,android,android-alertdialog,Android,Android Alertdialog,正如您从下面的代码中看到的,我有一个if和else语句,其中if是if,它将显示一个祝酒词。现在我想要的是,我希望显示一个包含一些文本和Ok按钮的警报,而不是显示toast @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (index==5){
Toast.makeText(getApplicationContext(), "More coming soon!", Toast.LENGTH_SHORT).show();
}else {
position2 = (index++);
}
String textValue = values[position2];
tv.setText(textValue);
Random RAND = new Random();
int position = RAND.nextInt(colors.length);
String nextValue = colors[position];
rl.setBackgroundColor(Color.parseColor(nextValue));
n.setBackgroundColor(Color.argb(00,00,00,00));
return true;
case MotionEvent.ACTION_UP:
n.setBackgroundColor(Color.argb(00,00,00,00));
return true;
default:
return false;
有人能帮我吗?如果你在活动课上
showDialog(this);
如果你不在活动课上
private Context mContext;
public void setContext(Context context) {
mContext = context;
}
showDialog(mContext);
功能
public void showDialog(Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setMessage("More coming soon!")
.setTitle("Your title here..")
.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
dialog.dismiss();
}
});
builder.show();
}
把它换成烤面包。
上下文通常是活动的上下文,因此如果您在活动中发送“this”
希望能有所帮助。试试看,如果卡住了,再问一次。谢谢,有什么解释吗?上下文有红色下划线?确定:当事件为ACTION_DOWN时,触摸得到事件,这意味着用户将手指放在屏幕上。同样,上下文通常是活动,但取决于调用函数的位置。如果它对您有帮助,请将其标记为答案。因此,我将活动放在上下文中,而不是放在上下文中?您可以使用getApplicationContext,我刚才说,如果您从活动类内部调用它,请使用“this”,我很抱歉我的误解,我只编写了大约两天的程序。你是说像这样?它仍然是红色下划线的