1
I have a layout with 2 lists, one complements the other, category and subcategory I would like, when inserting a subcategory by clicking add feed the database with the id of the category that is on the same line, I will connect a category to a subcategory.
For now the app is adding a subcategory to all categories as I haven’t been able to solve this yet.
Example, when I clicked to add a subcategory ("+" button next to the category) open a dialog to insert the name of the subcategory (I’m ready) and when clicking to add it linked the id of the category that was in the same line button (in the image the Acquisitions line) and insert in the idcategory key in the subcategory table.
Here is the layout, is a linear with an edittext, a button and a list, that inside it has another list where go the subclasses
Code entering the Subcategory - Categoriaadapter
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
final int auxPosition = position;
Categoria categoria = new Categoria();
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final RelativeLayout layout = (RelativeLayout)
inflater.inflate(R.layout.categoria_row,null);
final TextView categ = (TextView)
layout.findViewById(R.id.tvCat);
categ.setText(lista.get(position).getNome());
final ImageButton button = (ImageButton)
layout.findViewById(R.id.btAddSubCat);
button.setTag(categoria.getId());
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Adicionar subcategoria");
alert.setMessage("Digite um nome para a subcategoria:");
final EditText input = new EditText(context);
alert.setView(input);
alert.setPositiveButton("Adicionar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int idCategoria = (Integer) button.getTag();
subcategoria.setNome(input.getText().toString());
subcategoria.setIdCategoria(idCategoria);
SubCategoriaDAO subCategoriaDAO = new SubCategoriaDAO(context);
subCategoriaDAO.inserir(subcategoria);
}
});
alert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
return;
}
});
alert.show();
}
});
Where’s the code showing how far you’ve gone?
– Lollipop
You have to explain this layout. It’s confusing.
– Lollipop
There’s no use throwing an image and asking us to help in this or that.
– Lollipop
@Rafael, you’re right, it is a layout with 2 lists, 2 Adapters, I will put images and the code that makes add the subclass.
– Allan Chrystian