Note that there are some explanatory texts on larger screens.

plurals
  1. POSeparate listeners on TextView and ImageButton in a ListView
    primarykey
    data
    text
    <p>I wish to create a ListView, where each item in the list should contain a textview and an imageview next to it. Clicking on the textView should take me to another activity and clicking on the imageview/imagebutton should play an audio file. </p> <p>This is the relevant portion of the code written by me so far:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mDbHelper = new DbAdapter(this); mDbHelper.open(); temp=mDbHelper.fetchAllNotes(); startManagingCursor(temp); String[] from=new String[]{DbAdapter.KEY_TITLE}; int[] to= new int[]{R.id.tvList}; words = new SimpleCursorAdapter(Main.this, R.layout.emptylist, temp, from, to); Main.this.setListAdapter(words); ImageView ivSpeak=(ImageView) findViewById(R.id.ivSpeak); ivSpeak.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(Main.this, "Hi", Toast.LENGTH_SHORT).show(); } });} protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Intent i=new Intent(Main.this,WordDetail.class); i.putExtra(DbAdapter.KEY_ROWID, id); startActivity(i); } </code></pre> <p>The main.xml (layout for the entire activity) file is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/changedback"&gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:textFilterEnabled="true" android:background="@android:color/transparent" android:cacheColorHint="#00000000"&gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre> <p>The emptylist.xml (the layout for the individual items in the listview) file is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:background="@android:color/transparent"&gt; &lt;TextView android:id="@+id/tvList" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:layout_alignParentLeft="true" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerVertical="true" android:background="@android:color/transparent"/&gt; &lt;ImageView android:id="@+id/ivSpeak" android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/ic_launcher" android:layout_alignParentRight="true" android:focusable="false" android:background="@android:color/transparent"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The ivSpeak.setOnClickListener(new OnClickListener() is giving me a null pointer exception. Kindly help. I am quite new to Android</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload