You can solve this with a dialog.
When creating the dialog you need to define a layout in which you will be asked for the information you want to request regarding each table. Below is an example that can help you solve your problem.
dialog_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<EditText
android:id="@+id/value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:hint="Valor"
android:inputType="numberDecimal" /></LinearLayout>
In the class or Fragment in which you want to inflate the dialog you must add the following code:
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
final LayoutInflater inflater = getActivity().getLayoutInflater();
final View v = inflater.inflate(R.layout.dialog_layout, null);
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(v)
// Add action buttons
.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
String valorDigitado = ((EditText) v).getText().toString();
showToast();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
break;
When clicked on confirm(setPositiveButton) you must fetch all the data that has been filled in;
To save your information you can create an Arraylist of the Table class as follows:
ArrayList<Mesa> mesa = new ArrayList<Mesa>()
So every time one is clicked on to confirm you should create a table object and add it, suppose table has the total fields and tip then we would have:
public class Mesa{
private String valor;
private String gorjeta;
public String getGorjeta(){
return this.gorjeta;
}
public void setGorjeta(String gorjeta){
this.gorjeta = gorjeta;
}
public String getValor(){
return this.valor;
}
public void setValor(String valor){
this.valor = valor;
}
}
So here’s what you’d do:
Mesa m = new Mesa();
m.setValor("valor que sera obtido do dialog como no exemplo dessa resposta");
m.setGorjeta("valor que sera obtido do dialog como no exemplo dessa resposta");
mesa.add(posicaodoClick,m);
the value posicaClick you get through the setOnItemClickListener method that will give you the position that was clicked, this is necessary for you to keep track of which position was clicked, I believe you are using a gridView then it would be something like:
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
//chama dialog;
//preenche objeto do tipo mesa
//insere no ArrayList de Mesa
//mesa.add(position,objetoTipoMesa);
}
});
All you need is an Activity or, possibly better, a Dialogfragment.
– ramaral
Understood, but if I come back from this window, example, table 1 window, click table 2, insert the dice into it, table 1 will not get lost ne ? 'Cause that can’t happen.
– Nilzon Martins
You will need to create a system to store the data of each table, it can be a simple Arraylist or a database.
– ramaral