android - setOnItemClickListener not working on ListViewAdapter with custom layout -


i have problem onitemclicklistener event, doesn't anything, 3 nights i've spent trying solve problem , have nothing, hope can me.

i need control position of every row in listview, change value of textview or change checked status of radiobutton on desired positión, someting nameofradiobuton(atposition).setchecked(true) or txtarticulo(atposition).settext("it works").

the code bellow:

activity.java:

package com.example.ernesto.mitienditapuntodeventa;  import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.text.editable; import android.text.textwatcher; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.adapterview; import android.widget.button; import android.widget.edittext; import android.widget.imageview; import android.widget.listview; import android.widget.textview; import android.widget.toast;   public class catarticulosactivity extends actionbaractivity {     //declaracion de objetos     //declare     button btnagregar,btneditar,btneliminar;     imageview ivwipe;     listviewadapter_catarticulos adaptercatarticulos;     edittext txtfiltro;     string[] nomarticulo;     string[] unidad;     string[] precio;     integer[] idarticulo;      public static edittext haycambio;     public string cadenasql,conteosql;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_cat_articulos);          //creacion de tabla         //creatin table         sqlitedatabase db=getapplicationcontext().openorcreatedatabase("db", context.mode_private,null);         db.execsql("create table if not exists articulos(id int,articulo varchar,unidad varchar," +                 "precio double,existencia double,exismax double,exismin double);");          //enlace con el layout         //link layout         btnagregar=(button)findviewbyid(r.id.btnagregar);         btneditar=(button)findviewbyid(r.id.btneditar);         btneliminar=(button)findviewbyid(r.id.btneliminar);         ivwipe=(imageview)findviewbyid(r.id.ivwipe);         txtfiltro=(edittext)findviewbyid(r.id.txtfiltrar);         haycambio=(edittext)findviewbyid(r.id.txthaycambio);         haycambio.setenabled(false);         haycambio.setvisibility(view.invisible);          //boton agregar         //add button         btnagregar.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 edit_articulo_dialogo dialogfragment = new edit_articulo_dialogo();                 dialogfragment.show(getfragmentmanager(), "");             }         });          //boton agregar         //edit button         btneditar.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 //todo abrir dialogo para abrir el seleccionado                 //todo refrescar lista             }         });          //boton eliminar         //delete button         btneliminar.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 //todo eliminar el seleccionado                 //todo refrescar lista             }         });          //lo que se escribe en el edittext muestra coincidencias en el listview         //text in edittext refresh listview content filter         txtfiltro.addtextchangedlistener(new textwatcher() {             @override             public void beforetextchanged(charsequence charsequence, int i, int i1, int i2) {}             @override             public void ontextchanged(charsequence charsequence, int i, int i1, int i2) {}             @override             public void aftertextchanged(editable editable) {                 inicializaadaptador();             }         });          //detecta cuando hay un cambio en el edittext y refresca el contenido del listview         //detecs changes in table , refresh listview content         haycambio.addtextchangedlistener(new textwatcher() {             @override             public void beforetextchanged(charsequence charsequence, int i, int i1, int i2) {}             @override             public void ontextchanged(charsequence charsequence, int i, int i1, int i2) {}             @override             public void aftertextchanged(editable editable) {                 inicializaadaptador();             }         });          //reinicia el filtro         //reset filter         ivwipe.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 txtfiltro.settext("");                 inicializaadaptador();             }         });          //primer llenado del listview en el oncreate         //first load listview on oncreate         inicializaadaptador();     }      //esta clase asigna los valores al adapter     //this class send values adapter     public void inicializaadaptador(){          if (txtfiltro.gettext().tostring().equals("")){             conteosql="select count(*) articulos;";             cadenasql="select articulo,unidad,precio,id articulos order articulo;";         }else {             conteosql="select count(*) articulos articulo '%"+                     txtfiltro.gettext().tostring()+"%';";             cadenasql="select articulo,unidad,precio,id articulos articulo '%"+                     txtfiltro.gettext().tostring()+"%' order articulo;";         }          sqlitedatabase db=getapplicationcontext().openorcreatedatabase("db", context.mode_private,null);         int numeroregistros=0,pila=0;          cursor cverificanumeroregistro=db.rawquery(conteosql,null);         if (cverificanumeroregistro.movetofirst()){             numeroregistros=cverificanumeroregistro.getint(0);         }else {numeroregistros=0;}         cverificanumeroregistro.close();          if (numeroregistros>=1){             nomarticulo=new string[numeroregistros];             unidad=new string[numeroregistros];             precio=new string[numeroregistros];             idarticulo=new integer[numeroregistros];              cursor cagregavalpilas = db.rawquery(cadenasql,null);             if (cagregavalpilas.movetofirst()){                 {                     nomarticulo[pila]=cagregavalpilas.getstring(0);                     unidad[pila]=cagregavalpilas.getstring(1);                     precio[pila]=string.valueof(cagregavalpilas.getdouble(2));                     idarticulo[pila]=cagregavalpilas.getint(3);                     pila+=1;                 }while (cagregavalpilas.movetonext());             }             cagregavalpilas.close();              final listview listaarticulos=(listview)findviewbyid(r.id.lvarticulos);             adaptercatarticulos=new listviewadapter_catarticulos(this,nomarticulo,unidad,precio,idarticulo);             listaarticulos.setadapter(adaptercatarticulos);              listaarticulos.setonitemclicklistener(new adapterview.onitemclicklistener() {                 @override                 public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {                     final textview txt =(textview) view.findviewbyid(r.id.txtarticulo);                     tostadora(txt.gettext().tostring());                 }             });         }else {             if (txtfiltro.gettext().tostring().equals("")){                 tostadora("no hay registros para presentar");             }else {                 tostadora("la busqueda no permite filtar mas registros");             }         }     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_cat_articulos, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     }      public void tostadora(string mensaje){         toast.maketext(getapplicationcontext(),mensaje,toast.length_short).show();     } } 

layout.xml:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"     android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin"     android:orientation="vertical"     tools:context="com.example.ernesto.mitienditapuntodeventa.catarticulosactivity">      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancelarge"         android:text="catálogo de artículos"         android:id="@+id/textview12"         android:layout_gravity="center_horizontal" />      <edittext         android:layout_width="0dp"         android:layout_height="0dp"         android:id="@+id/txthaycambio"         android:text="1" />      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="wrap_content">          <edittext             android:layout_width="0dp"             android:layout_height="wrap_content"             android:id="@+id/txtfiltrar"             android:hint="filtrar"             android:layout_weight="1"             android:layout_margintop="7dp" />          <imageview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/ivwipe"             android:src="@drawable/wipe" />     </linearlayout>      <listview         android:layout_width="match_parent"         android:layout_height="0dp"         android:id="@+id/lvarticulos"         android:layout_weight=".99"         android:choicemode="singlechoice"         android:layout_margintop="7dp"         android:descendantfocusability="blocksdescendants"/>      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal">          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="agregar"             android:id="@+id/btnagregar"             android:layout_weight=".333" />          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="editar"             android:id="@+id/btneditar"             android:layout_weight=".333" />          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="eliminar"             android:id="@+id/btneliminar"             android:layout_weight=".333" />     </linearlayout> </linearlayout> 

listviewadapter_catarticulos.java:

package com.example.ernesto.mitienditapuntodeventa;  import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.radiobutton; import android.widget.textview;  /**  * created ernesto on 10/07/2015.  */ public class listviewadapter_catarticulos extends baseadapter {      context context;     string[] nomarticulo;     string[] unidad;     string[] precio;     integer[] idarticulo;     layoutinflater inflater;      public listviewadapter_catarticulos(context context,string[] nomarticulo,string[] unidad,                                         string[] precio, integer[] idarticulo){         this.context=context;         this.nomarticulo=nomarticulo;         this.unidad=unidad;         this.precio=precio;         this.idarticulo=idarticulo;     }      @override     public int getcount() {         return nomarticulo.length;     }      @override     public object getitem(int i) {         return idarticulo;     }      @override     public long getitemid(int i) {         return 0;     }      @override     public view getview(final int i, view view, viewgroup viewgroup) {          final textview tvnomarticulo,tvunidad,tvprecio,tvidarticulo;         final radiobutton rbtnseleccionado;         inflater=(layoutinflater)context.getsystemservice(context.layout_inflater_service);          view itemview=inflater.inflate(r.layout.lista_catalogoarticulos,viewgroup,false);          tvnomarticulo=(textview)itemview.findviewbyid(r.id.tvnomarticulo);         tvunidad=(textview)itemview.findviewbyid(r.id.tvunidad);         tvprecio=(textview)itemview.findviewbyid(r.id.tvprecio);         tvidarticulo=(textview)itemview.findviewbyid(r.id.tvid);         rbtnseleccionado=(radiobutton)itemview.findviewbyid(r.id.rbtnartseleccionado);          tvnomarticulo.settext(nomarticulo[i]);         tvunidad.settext(tvunidad.gettext().tostring() + unidad[i]);         tvprecio.settext(tvprecio.gettext().tostring() + precio[i]);         tvidarticulo.settext(idarticulo[i].tostring());         rbtnseleccionado.settext(null);          return itemview;     } } 

lista_catalogoarticulos.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="match_parent">      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_margintop="5dp"         android:layout_marginbottom="5dp">          <radiobutton             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/rbtnartseleccionado"             android:checked="false"             android:layout_gravity="center"             android:layout_margin="5dp" />          <linearlayout             android:orientation="vertical"             android:layout_width="fill_parent"             android:layout_height="wrap_content">              <textview                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:textappearance="?android:attr/textappearancemedium"                 android:text="nombre de articulo"                 android:id="@+id/tvnomarticulo" />              <linearlayout                 android:orientation="horizontal"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content">                  <textview                     android:layout_width="0dp"                     android:layout_height="0dp"                     android:text="id"                     android:id="@+id/tvid"                     android:layout_weight="0" />                  <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:textappearance="?android:attr/textappearancesmall"                     android:text="unidad: "                     android:id="@+id/tvunidad"                     android:layout_weight=".333" />                  <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:textappearance="?android:attr/textappearancesmall"                     android:text="precio: "                     android:id="@+id/tvprecio"                     android:layout_weight=".33" />              </linearlayout>         </linearlayout>      </linearlayout> </linearlayout> 

i not think updating list when edit text changes. need notify adapter data has changed. adaptercatarticulos.notifydatasetchanged();

    final listview listaarticulos=(listview)findviewbyid(r.id.lvarticulos);         adaptercatarticulos=new listviewadapter_catarticulos(this,nomarticulo,unidad,precio,idarticulo);         listaarticulos.setadapter(adaptercatarticulos);          listaarticulos.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {                 final textview txt =(textview) view.findviewbyid(r.id.txtarticulo);                 tostadora(txt.gettext().tostring());             }         });     adaptercatarticulos.notifydatasetchanged();     }else {         if (txtfiltro.gettext().tostring().equals("")){             tostadora("no hay registros para presentar");         }else {             tostadora("la busqueda no permite filtar mas registros");         }     } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -