I am developing an android media player. I am new to ANDROID. I am using the following code to show all the music from a query result. I want every song once, but it showing a single song more than once and ignoring many others, if I set the text size in the adapter view as in the following code. How can I set the text size in the adapter view and avoid this problem?
Thank u
public class MusicAdapter extends BaseAdapter {
private Context mContext;
public MusicAdapter(Context c) {
mContext = c;
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
TextView tv = new TextView(mContext.getApplicationContext());
tv.setTextSize(25); //THE PROBLEM IS HERE
String id = null;
if (convertView == null) {
music_column_index = musicCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
musicCursor.moveToPosition(position);
id = musicCursor.getString(music_column_index);
music_column_index = musicCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
musicCursor.moveToPosition(position);
String artist = musicCursor.getString(music_column_index);
id += "Artist:" + artist;
tv.setText(id);
} else
tv = (TextView) convertView;
return tv;
}
}
I have solved it by using SimpleCursorAdapter like below. It is a built in adapter, which is really smart. This link helped me a lot
And you should never set android:layout_height=”wrap_content” of a listview. It causes the repeating occurrence of list items.