Я хочу создать ListView, где каждый элемент в списке должен содержать текстовое представление и изображение рядом с ним.Нажатие на textView должно привести меня к другому занятию, а нажатие на кнопку imageview / imagebutton должно воспроизвести аудиофайл.
Это релевантная часть кода, написанного мной до сих пор:
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);
}
Файл main.xml (макет для всей деятельности):
<?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="wrap_content" android:background="@drawable/changedback">
<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">
</ListView> </LinearLayout>
Файл emptylist.xml (расположение отдельных элементов в просмотре списка):
<?xml version="1.0" encoding="utf-8"?>
<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">
<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"/>
<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"/>
</RelativeLayout>
ivSpeak.setOnClickListener (new OnClickListener () дает мне исключение нулевого указателя.Я новичок в Android