Как отобразить диалоговое окно с предупреждением на Android?

Я никогда не пробовал, но будет ли .setArray () делать то, что вы ищете?

Обновление: очевидно, нет. Кажется, что setArray работает с java.sql.Array, который исходит из столбца ARRAY, который вы извлекли из предыдущего запроса, или подзапроса с столбцом ARRAY.

983
задан 9 revs, 7 users 37% 3 November 2016 в 01:56
поделиться

4 ответа

    LayoutInflater inflater = LayoutInflater.from(HistoryActivity.this);
    final View vv = inflater.inflate(R.layout.dialog_processing_tts, null);
    final AlertDialog.Builder alert = new AlertDialog.Builder(
            HistoryActivity.this);
    alert.setTitle("Delete");
    alert.setView(vv);
    alert.setCancelable(false)
            .setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    databaseHelperClass.deleteHistory(list.get(position).getID());
                    list.clear();
                    setAdapterForList();

                }
            })
            .setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });

    final AlertDialog dialog = alert.create();
    dialog.show();
0
ответ дан Noman Zafar 4 November 2019 в 06:26
поделиться
  • 1
    @RC: где Java будет только работать с Win7 / Win2008, я считаю. – Michael Mao 14 October 2010 в 05:51

Вы можете использовать AlertDialog для этого и построить один, используя его Class класс. Пример ниже использует конструктор по умолчанию, который принимает только в контексте , поскольку диалоговое окно наследует правильную тему из контекста, который вы передаете, но есть также конструктор, который позволяет вам указать конкретный ресурс тема как Второй параметр, если вы хотите это сделать.

new AlertDialog.Builder(context)
    .setTitle("Delete entry")
    .setMessage("Are you sure you want to delete this entry?")

    // Specifying a listener allows you to take an action before dismissing the dialog.
    // The dialog is automatically dismissed when a dialog button is clicked.
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // Continue with delete operation
        }
     })

    // A null listener allows the button to dismiss the dialog and take no further action.
    .setNegativeButton(android.R.string.no, null)
    .setIcon(android.R.drawable.ic_dialog_alert)
    .show();
1763
ответ дан 19 December 2019 в 20:20
поделиться

Просто будьте осторожны, когда хотите закрыть диалоговое окно - используйте dialog.dismiss () . В своей первой попытке я использовал dismissDialog (0) (который я, вероятно, скопировал откуда-то), который иногда работает. Использование объекта, поставляемого системой, кажется более безопасным выбором.

7
ответ дан 19 December 2019 в 20:20
поделиться

Сегодня я сделаю пример alertdialog в андроиде с дисплеем 2 опций да Шаг 1. создайте activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context=".MainActivity"
    android:background="#d2ffe8"
    >
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is a TextView."
        android:textSize="35dp"
        android:textColor="#ff3550"
        />
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hide TextView"
        android:layout_below="@id/tv"
        />
</RelativeLayout>

Шаг 2. создайте класс MainActivity.java

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Get reference of widgets from XML layout
        final RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
        Button btn = (Button) findViewById(R.id.btn);
        final TextView tv = (TextView) findViewById(R.id.tv);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Build an AlertDialog
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("Select your answer.");
                builder.setMessage("Are you sure to hide?");
                // Set the alert dialog yes button click listener
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        tv.setVisibility(View.GONE);
                    }
                });
                builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        Toast.makeText(getApplicationContext(),
                                "No Button Clicked",Toast.LENGTH_SHORT).show();
                    }
                });
                AlertDialog dialog = builder.create();
                // Display the alert dialog on interface
                dialog.show();
            }
        });
  }
}

, который Вы видите alertdialog в андроиде в

0
ответ дан 19 December 2019 в 20:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: