Capture Form Expandlelistview Fields

Asked

Viewed 34 times

0

I have a ExpandleListView with each item having its own layout. This layout has Editexts, checkbox, etc. I need to capture what is typed and selected in each item of the expandle listview. Has anyone ever used this approach?

 Adapter
public class AneurismaTratamentoAdapter extends BaseExpandableListAdapter {
    private List<String> lstGrupos;
    private HashMap<String, List<String>> lstItensGrupos;
    private Context context;
    private String aneurismaTratamentoEntity;
    private ArrayList<EditText> listaEditiText  = new ArrayList<EditText>();
    private ItemSuporte holder = null;
    public List<ItemSuporte> listaHolder = new ArrayList<>();

    public AneurismaTratamentoAdapter(Context context, List<String> grupos) {
        this.context = context;
        lstGrupos = grupos;
    }

    @Override
    public int getGroupCount() {
        return lstGrupos.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return lstGrupos.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return lstGrupos.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return lstGrupos.get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_item_group_aneurisma, null);
        }
        else{
            convertView.getTag();
        }

        ImageView image = (ImageView) convertView.findViewById(R.id.im_icon_list);

        if(groupPosition == 0 || groupPosition > 0){
            int iamgeResourceId = isExpanded ? R.mipmap.ic_seta_up_preto : R.mipmap.ic_seta_down_preto;
            image.setImageResource(iamgeResourceId) ;
            image.setVisibility(View.VISIBLE);
            }
        else{
            image.setVisibility(View.INVISIBLE);
        }

        TextView tvGrupo = (TextView) convertView.findViewById(R.id.ed_item_menu_paciente);

        tvGrupo.setText((String) getGroup(groupPosition));
        return convertView;
    }



    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        final ItemSuporte holder;

        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_aneurisma,null);
            holder = new ItemSuporte();
            holder.aneurismaLargura = (EditText) convertView.findViewById(R.id.et_largura);
            holder.aneurismaComprimento = (EditText)  convertView.findViewById(R.id.ed_comprimento);
            holder.containner = (View) convertView.findViewById(R.id.container);

            convertView.setTag(holder);
        }
        else{
            holder = (ItemSuporte) convertView.getTag();
        }
        // Passar os parâmtros aqui caso tenha que preencher.
      return convertView;
    }

    public void clickButtonVerFotosAneurisma(final ItemSuporte holder){
        if(holder != null){
            holder.bt_ver_fotos.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    irTelaImagensAneurisma();
                }
            });

        }
    }

    public void clickButtonEnviarFotoAneurisma(final ItemSuporte holder){
        if(holder != null){
            holder.bt_enviar_foto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    irTelaEnviarFoto();
                }
            });
        }
    }

    public void irTelaImagensAneurisma(){
        Intent it = new Intent(context, ImagensAneurismaPacienteActivity.class);
        context.startActivity(it);
    }

    public void irTelaEnviarFoto(){

    }

    private class ItemSuporte {
        EditText aneurismaLargura;
        EditText aneurismaComprimento;
        Button bt_ver_fotos;
        Button bt_enviar_foto;
        View containner;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}

1 answer

0

In order to handle click events on the elements that make up the layout of the child items in the list, you can add click listeners for each element within the method getChildView() from your Adapter, as this is the method that defines the layout of the child elements:

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,View convertView, ViewGroup parent){

    LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    convertView = mInflater.inflate(R.layout.expandable_list_item_filho, null);     

    EditText mEditText = (EditText)convertView.findViewById(R.id.editText);
    TextView mTextView = (TextView)convertView.findViewById(R.id.textView);


    mEditText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // Seu código
        }
    });


    mTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            //Seu código
        }
    });

    return convertView;
}
  • How can I store the data so that when closing a group, your respective child does not lose the data?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.