Я никогда не пробовал, но будет ли .setArray () делать то, что вы ищете?
Обновление: очевидно, нет. Кажется, что setArray работает с java.sql.Array, который исходит из столбца ARRAY, который вы извлекли из предыдущего запроса, или подзапроса с столбцом ARRAY.
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();
Вы можете использовать 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();
Просто будьте осторожны, когда хотите закрыть диалоговое окно - используйте dialog.dismiss ()
. В своей первой попытке я использовал dismissDialog (0)
(который я, вероятно, скопировал откуда-то), который иногда работает. Использование объекта, поставляемого системой, кажется более безопасным выбором.
Сегодня я сделаю пример 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 в андроиде в