Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7736813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:50:20+00:00 2026-06-01T07:50:20+00:00

I have a xml file with an ImageView with the propiety of android:onClick=playSound ,

  • 0

I have a xml file with an ImageView with the propiety of android:onClick="playSound", and it works fine in the first loaded list view in my Activity: when I click in this ImageView that it’s located in every row of the listview, the method playSound runs.

The problem is that I have in the top of this Activity an EditText to filter the content loaded of in the listview, to filter the elements/rows, searching by name for example (like a dictionary). When I write something, and the listview have less elements, if I click onto the same ImageView of any row, a force close exception appears: NoSuchMethodException: playSound

It seems onClick can’t find the method playSound inside the Activity, but it is there.

The Activity

public class ListaCaracteres extends Activity{

private Context context;
private Cursor c;
private SQLiteDatabase hanyuDB;
private HanyuSQLHelper hanyuDBHelper;
private AdapterListaCaracteres adapter;
private ListView listaCaracteres;
private EditText buscador;
private ImageView play;
private MediaPlayer mediaPlayer;
private String texto = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(es.hsk.ap.R.layout.lista_caracteres);

    /*
     * Query a la base de datos, obtenemos todos los lugares en Cursor
     */
    try{
        hanyuDBHelper = new HanyuSQLHelper(this);
        hanyuDB = hanyuDBHelper.getReadableDatabase();
        c = hanyuDB.rawQuery(" SELECT * FROM Caracteres ", null);
    }
    catch(SQLiteException ex)
    {
        Toast mensajeError=Toast.makeText(getApplicationContext(), "Error accediendo a los datos", Toast.LENGTH_SHORT);
        mensajeError.show();
        Log.e("LogLugares", "Error en getReadableDatabase()", ex);
    }     


    /*
     * Utilizamos nuestro Adapter AdapterListaCaracteres con el contenido del Cursor
     */
    adapter = new AdapterListaCaracteres(this,c, true);
    listaCaracteres = (ListView)findViewById(es.hsk.ap.R.id.listaCaracteres);   
    listaCaracteres.setAdapter(adapter);       

    /*
     * Localizamos y damos funciona al buscador
     */
    buscador = (EditText)findViewById(R.id.buscador); 

    buscador.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            texto = buscador.getText().toString();

            c = hanyuDB.rawQuery(
                    " SELECT * FROM Caracteres WHERE significado LIKE '%"
                            + texto + "%'", null);

            AdapterListaCaracteres adapter2 = new AdapterListaCaracteres(getApplicationContext(), c, false);
            listaCaracteres.setAdapter(adapter2);

            return false;
        }
    });

    /*
     * Ponemos acción al clic sobre un elemento del listview
     */
    listaCaracteres.setOnItemClickListener(new OnItemClickListener(){
        public void onItemClick(AdapterView<?> parent, View view, int position, long id){

            /*
             * Al hacer clic se inicia activity MostrarCaracter
             * El Intent enviado lleva como parámetro el id del objeto a mostrar
             */
            if(texto!=null){
                c = hanyuDB.rawQuery(
                        " SELECT * FROM Caracteres WHERE significado LIKE '%"
                                + texto + "%'", null);
                c.moveToPosition(position);
                position=c.getInt(0)-1;
            }


            Intent intent=new Intent();
            intent.setClass(getApplicationContext(), MostrarCaracter.class);                    

            intent.putExtra("idObjeto", position);
            startActivity(intent);
        }
    }); 
}


/*
 * Método para reproducir sonido de carácter
 */
public void playSound(View view){
    int posicion=listaCaracteres.getPositionForView(view);
    if(texto!=null){
        c = hanyuDB.rawQuery(
                " SELECT * FROM Caracteres WHERE significado LIKE '%"
                        + texto + "%'", null);
        c.moveToPosition(posicion);
        posicion=c.getInt(0)-1;
    }

    c = hanyuDB.rawQuery(" SELECT audio FROM Caracteres WHERE _id="+(posicion+1), null);
    c.moveToFirst();
    String audio=c.getString(0);
    int resID = getResources().getIdentifier(audio, "raw", "es.hsk.ap");
    mediaPlayer = MediaPlayer.create(this, resID);
    mediaPlayer.start();
}

The xml inflated file in my adapter, who has the ImageView (id play) to be clickable and with onClick action

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="5dp" >

<TextView
    android:id="@+id/caracter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:paddingLeft="5dp"
    android:paddingRight="15dp"
    android:paddingBottom="5dp"
    android:textSize="28dp" />

<TextView
    android:id="@+id/pinyin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="24dp" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="right" >

    <ImageView
        android:id="@+id/play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/icono"
        android:paddingRight="7dp"
        android:onClick="playSound"
        android:src="@drawable/speaker" />
</LinearLayout>

</TableRow>

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="5dp" >

<TextView
    android:id="@+id/significado"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"
    android:textSize="16dp" />

</TableRow>

Logcat:

    04-04 21:36:07.144: E/AndroidRuntime(5569): Uncaught handler: thread main exiting due to uncaught exception
04-04 21:36:07.164: E/AndroidRuntime(5569): java.lang.IllegalStateException: Could not find a method reproducir(View) in the activity
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.View$1.onClick(View.java:2020)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.View.performClick(View.java:2364)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.View.onTouchEvent(View.java:4179)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.View.dispatchTouchEvent(View.java:3709)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.os.Looper.loop(Looper.java:123)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.app.ActivityThread.main(ActivityThread.java:4363)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at java.lang.reflect.Method.invokeNative(Native Method)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at java.lang.reflect.Method.invoke(Method.java:521)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at dalvik.system.NativeStart.main(Native Method)
04-04 21:36:07.164: E/AndroidRuntime(5569): Caused by: java.lang.NoSuchMethodException: reproducir
04-04 21:36:07.164: E/AndroidRuntime(5569):     at java.lang.ClassCache.findMethodByName(ClassCache.java:308)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at java.lang.Class.getMethod(Class.java:1014)
04-04 21:36:07.164: E/AndroidRuntime(5569):     at android.view.View$1.onClick(View.java:2017)

my custom adapter:

public class AdapterListaCaracteres extends CursorAdapter{

private Context  mContext;
private Cursor  datos;
private boolean aRequery;
private LayoutInflater inflater;

/*
 * Constructor de la clase
 */
public AdapterListaCaracteres(Context  context, Cursor  c, boolean autoRequery){
    super(context, c, autoRequery);
    this.mContext = context;
    this.datos = c;
    this.aRequery=autoRequery;
}

public void reproducir(View view){
}

/*
 * Métodos
 */
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return datos.getCount();
}

@Override
public Object  getItem(int position) {
    // TODO Auto-generated method stub
    return datos.getString(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

public View  getView(int position, View  convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    View item = convertView;
    ViewHolder holder;

    inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    datos.moveToPosition(position);

    //Comprobamos si el item existe para reaprovecharlo
    if(item==null){
        try{
            item = inflater.inflate(es.hsk.ap.R.layout.caracter, null);
        }
        catch(InflateException ex)
        {
            // lo que querais hacer en este caso,mostrar un toast o lo que sea
        }


        holder = new ViewHolder();
        holder.caracter = (TextView)item.findViewById(es.hsk.ap.R.id.caracter);
        holder.pinyin = (TextView)item.findViewById(es.hsk.ap.R.id.pinyin);
        holder.significado = (TextView)item.findViewById(es.hsk.ap.R.id.significado);
        holder.audio = (ImageView)item.findViewById(es.hsk.ap.R.id.play);

        item.setTag(holder);
    }
    else{
        holder = (ViewHolder)item.getTag();
    }           

    holder.caracter.setText(datos.getString(2));            
    holder.pinyin.setText(datos.getString(3));  
    holder.significado.setText(datos.getString(4));

    return item;

}



/*
 * Utilizamos clase ViewHolder para obtener IDs de objetos View inflados anteriormente
 * (objetos hijos del objeto convertView) y así reparovecharlos para ahorrar recursos 
 * y batería al hacer scroll. Se localizan mediante la propiedad Tag
 */
static class ViewHolder{
    TextView caracter;
    TextView pinyin;
    TextView significado;
    ImageView audio;
}



@Override
public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub

}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    // TODO Auto-generated method stub
    return null;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:50:22+00:00Added an answer on June 1, 2026 at 7:50 am

    onClick will look for the method on the Context instance. Make sure that the Context used to inflate ListView items is your Activity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have <.ImageView> enter code here s(icons) in my android layout xml file, which
I have the following XML file to define my frame animation: <animation-list xmlns:android=http://schemas.android.com/apk/res/android android:oneshot=false>
In my .xml file i have this format: <LinearLayout android:layout_orientation=vertical...> <ImageView>... </ImageView> <ScrollView ...>
I have an ImageView in my main.xml file: <ImageView android:id=@+id/pageImage android:layout_width=270dp android:layout_height=45dp android:layout_alignParentLeft=true android:layout_alignParentTop=true
In my xml file, I have declared two imageview and later I add image
I have an xml file with the following structure: <main_tag> <first> <tag1>val1</tag1> <conf> <tag2>val2</tag2>
I have xml file and that create view and i pass that screen shot
I have this xml file <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical >
I have this XML file: <?xml version=1.0 encoding=UTF-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent> <Button
I have my ImageView laid out in an .xml file and in my main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.