標題:
AlertDialog 設定Dialog點擊螢幕不消失
[打印本頁]
作者:
周政輝
時間:
2018-11-3 11:05
標題:
AlertDialog 設定Dialog點擊螢幕不消失
.setCancelable(false)
作者:
黃璽安
時間:
2018-11-3 11:12
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("確認視窗");
builder.setIcon(R.mipmap.ic_launcher);
builder.setCancelable(false);
builder.setMessage("即將離開應用程式!");
builder.setPositiveButton("確認", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
builder.setCancelable(false);
break;
複製代碼
作者:
陳泓瑜
時間:
2018-11-3 11:13
package com.example.red.red;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class RED extends AppCompatActivity {
int img[] = new int[6];
int i=0;
Button btn1;
Button btn2;
ImageView imageView;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_red);
img[0]=R.drawable.img01;
img[1]=R.drawable.img02;
img[2]=R.drawable.img03;
img[3]=R.drawable.img04;
img[4]=R.drawable.img05;
img[5]=R.drawable.img06;
btn1= (Button) findViewById(R.id.button);
btn2= (Button) findViewById(R.id.button2);
imageView= (ImageView) findViewById(R.id.imageView);
imageView.setImageResource(img[0]);
textView= (TextView) findViewById(R.id.textView);
textView.setText("第1/6張");
}
public void next(View view) {
if(!(i+1>=img.length))
{
imageView.setImageResource(img[++i]);
textView.setText("第" + (i + 1) + "/6張");
if(i==5)
{
new AlertDialog.Builder(RED.this)
.setTitle("沒了!")
.setMessage("蘇鋪乳癌死馬的法克!")
.setCancelable(false)
.setPositiveButton("Goods", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Fuck", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNeutralButton("Jesus", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
}
public void last(View view) {
if(!(i-1<0))
{
imageView.setImageResource(img[--i]);
textView.setText("第" + (i+1) + "/6張");
}
}
}
複製代碼
作者:
蔡季樺
時間:
2018-11-3 11:14
package com.example.plantsai.myapplicationpic;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button p;
Button n;
ImageView iv;
int num = 1;
TextView tv;
int[] image = new int[6];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init()
{
n = findViewById(R.id.button2);
p = findViewById(R.id.button);
iv = findViewById(R.id.imageView);
tv = findViewById(R.id.textView);
image[0] = R.drawable.img01;
image[1] = R.drawable.img02;
image[2] = R.drawable.img03;
image[3] = R.drawable.img04;
image[4] = R.drawable.img05;
image[5] = R.drawable.img06;
iv.setImageResource(image[0]);
rename();
n.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 6)
{
num++;
rename();
iv.setImageResource(image[num-1]);
}else{
rename();
new AlertDialog.Builder(MainActivity.this)
.setTitle("錯誤訊息")
.setMessage("已經到底了!")
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
});
p.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 1)
{
num--;
rename();
iv.setImageResource(image[num-1]);
}else{
rename();
new AlertDialog.Builder(MainActivity.this)
.setTitle("錯誤訊息")
.setMessage("已經到底了!")
.setCancelable(false)
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
});
}
public void rename()
{
tv.setText("第"+num+"/6張");
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<android.widget.AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="289dp"
android:layout_height="219dp"
android:layout_x="50dp"
android:layout_y="136dp"
app:srcCompat="@drawable/img01"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="187dp"
android:contentDescription="@string/app_name"/>
<Button
android:id="@+id/button"
android:layout_width="127dp"
android:layout_height="wrap_content"
android:layout_x="63dp"
android:layout_y="437dp"
android:text="Previous"
tools:layout_editor_absoluteX="80dp"
tools:layout_editor_absoluteY="429dp" />
<Button
android:id="@+id/button2"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_x="206dp"
android:layout_y="439dp"
android:text="Next"
tools:layout_editor_absoluteX="285dp"
tools:layout_editor_absoluteY="227dp" />
<TextView
android:id="@+id/textView"
android:layout_width="174dp"
android:layout_height="44dp"
android:layout_x="0dp"
android:layout_y="0dp"
android:text="TextView"
tools:layout_editor_absoluteX="59dp"
tools:layout_editor_absoluteY="29dp" />
</android.widget.AbsoluteLayout>
複製代碼
作者:
李知易
時間:
2018-11-9 20:44
本帖最後由 李知易 於 2018-11-9 21:14 編輯
package com.example.user.hw20181105;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
int image[]=new int[6];
int index=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)findViewById(R.id.imageView);
this.setTitle("第"+(index+1)+"/6張");
image[0]=R.drawable.img01;
image[1]=R.drawable.img02;
image[2]=R.drawable.img03;
image[3]=R.drawable.img04;
image[4]=R.drawable.img05;
image[5]=R.drawable.img06;
imageView.setImageResource(image[0]);
}
public void previous(View view) {
if (index > 0) {
imageView.setImageResource(image[--index]);
this.setTitle("第" + (index + 1) + "/6張");
}else{
final AlertDialog dialog =new AlertDialog.Builder(MainActivity.this)
.setTitle("Error")
.setMessage("This is the first page!")
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),"Okay", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),"Cancel", Toast.LENGTH_SHORT).show();
}
})
.show();
}
}
public void next(View view) {
if (index < image.length - 1) {
imageView.setImageResource(image[++index]);
this.setTitle("第" + (index + 1) + "/6張");
}else{
final AlertDialog dialog =new AlertDialog.Builder(MainActivity.this)
.setTitle("Error")
.setMessage("It is already the last page!")
.setCancelable(false)
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Okay", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Cancel", Toast.LENGTH_SHORT).show();
}
})
.setCancelable(false)
.show();
}
}
public void left(View view) {
}
}
複製代碼
作者:
張健勳
時間:
2018-11-20 19:28
package com.smcs.yingwu.newalertdialog;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button back;
Button next;
ImageView ImageView;
int num = 1;
TextView textView;
int[] image = new int[6];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init()
{
next = findViewById(R.id.button2);
back = findViewById(R.id.button);
ImageView = findViewById(R.id.imageView);
textView = findViewById(R.id.textView);
image[0] = R.drawable.img01;
image[1] = R.drawable.img02;
image[2] = R.drawable.img03;
image[3] = R.drawable.img04;
image[4] = R.drawable.img05;
image[5] = R.drawable.img06;
ImageView.setImageResource(image[0]);
rename();
next.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 6)
{
num++;
rename();
ImageView.setImageResource(image[num-1]);
}else{
rename();
new AlertDialog.Builder(MainActivity.this)
.setTitle("錯誤訊息")
.setMessage("已經到底了!")
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
});
back.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 1)
{
num--;
rename();
ImageView.setImageResource(image[num-1]);
}else{
rename();
new AlertDialog.Builder(MainActivity.this)
.setTitle("錯誤訊息")
.setMessage("已經到底了!")
.setCancelable(false)
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
});
}
public void rename()
{
textView.setText("第"+num+"/6張");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2