I can not get the text from a selected item in a listview...pleeeeasss help.

Posted by Miguel on Stack Overflow See other posts from Stack Overflow or by Miguel
Published on 2010-03-30T15:09:37Z Indexed on 2010/03/30 15:13 UTC
Read the original article Hit count: 241

Filed under:
|

I always get an ClassCastException error... i do not what else to do... - I'm using a data biding concept to populated the listview from a sqlite3 database. - I just want to get the selected item text after a long press click.

This is the code of the activity:

public class ItemConsultaGastos extends ListActivity {

private DataHelper dh ; TextView seleccion;

private static String[] FROM = {DataHelper.MES, DataHelper.ANO};  
private static int[] TO =  {R.id.columnaMes, R.id.columnaAno };

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.muestrafechas);

    this.dh = new DataHelper(this);
    Cursor cursor = dh.selectAllMeses();


    startManagingCursor(cursor);

    this.mostrarFechas(cursor);

    ListView lv = getListView();
    lv.setOnItemLongClickListener(new OnItemLongClickListener(){
     @Override
     public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int row, long arg3) {

               //here is where i got the classCastException.
               String[] tmp = (String[]) arg0.getItemAtPosition(row);

        //tmp[0] ist the Text of the first TextView displayed by the  clicked ListItem 
        Log.w("Gastos: ", "El texto: " + tmp[0].toString());



        return true;
            }
 });

}

private void mostrarFechas(Cursor cursor) {

   SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.muestrafechasitem,cursor, FROM, TO);
   setListAdapter(adapter);

}

}

///// This is the xml where a define the rows to show on the listview

   <TextView
 android:id="@+id/espacio"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="    " />
   <TextView
   android:id="@+id/columnaAno"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textSize="20sp" 
   android:layout_toRightOf="@+id/espacio"/>
   <TextView
 android:id="@+id/separador1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="            --             "
 android:layout_toRightOf="@+id/columnaAno"
 android:textSize="20sp" />
   <TextView
   android:id="@+id/columnaMes"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_toRightOf="@+id/separador1" 
   android:textSize="20sp"/> 

© Stack Overflow or respective owner

Related posts about listview

Related posts about android