I have the following LinearLayout
with a GridView
in it:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <GridView android:id="@+id/songs_grid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:columnWidth="250dp" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" /> </LinearLayout>
GridView
data is provided by a custom adapter (using a simple ViewHolder
):
public class SongsAdapter extends BaseAdapter { private Context context; private LayoutInflater mInflater; private ArrayList<Song> songList; public SongsAdapter(Context context, ArrayList<Song> songList) { this.context = context; this.songList = songList; mInflater = LayoutInflater.from(this.context); } @Override public int getCount() { return songList.size(); } public Object getItem(int position) { return songList.get(position); } public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { SongViewHolder viewHolder; if (convertView == null) { convertView = mInflater.inflate(R.layout.song_list_item, null); viewHolder = new SongViewHolder();
When the application starts, it gets a list of songs (from xml, but currently uses a manually entered list) and passes it to my adapter, and then sets OnItemClickListener
:
GridView gridView = (GridView) findViewById(R.id.songs_grid); gridView.setAdapter(new SongsAdapter(this, fk.getSongList())); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { LinearLayout layout = (LinearLayout)view; TextView songTitle = (TextView)layout.findViewById(R.id.song_title); Song song = fk.getSong((String) songTitle.getText()); if(song != null) { Intent play = new Intent(getBaseContext(), Play.class); startActivity(play); } } });
When I first implemented this code, everything worked fine, and I'm sure I haven't changed anything. I tried to make a text to scroll the song name in the layout if it was too long, but could not get it to work. At this point, I found that the click stops working. I have now deleted (I believe) all this code, but it still doesn't work.
When I touch / click (whatever you call) nothing happens. no errors.
Is there something wrong with my code that might cause this problem?
neildeadman
source share