I am trying to configure OnItemClickListener for elements in my gridview. For some reason, the onItemCLick method in the listener is never called.
Listener and adapter settings:
UsersAdapter usersAdapter = new UsersAdapter(venueUsers); gridView.setAdapter(usersAdapter); gridView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Intent intent = new Intent(Users.this, com.roqbot.client.login.Profile.class); intent.putExtra("idUser", id); startActivity(intent); } });
My adapter:
private class UsersAdapter extends BaseAdapter implements ListAdapter { private JSONArray users; private UsersAdapter(JSONArray users) { this.users = users; } public int getCount() { return users.length(); } public JSONObject getItem(int position) { return users.optJSONObject(position); } public long getItemId(int position) { return users.optJSONObject(position).optInt("idUser"); } public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = Users.this.getLayoutInflater().inflate(R.layout.user_icon, null); JSONObject user = getItem(position); TextView username = (TextView) convertView.findViewById(R.id.username); username.setText(user.optString("sName")); TextView userScore = (TextView) convertView.findViewById(R.id.userScore); int iDJScore = user.optInt("iDJScore"); if (iDJScore > 0) { userScore.setText(Integer.toString(iDJScore)); } else { userScore.setVisibility(TextView.INVISIBLE); ((ImageView) convertView.findViewById(R.id.userScoreBg)).setVisibility(View.INVISIBLE); } TextView userLevel = (TextView) convertView.findViewById(R.id.userLevel); userLevel.setText(user.optString("iDJLevel")); TextView userMatch = (TextView) convertView.findViewById(R.id.userMatch); ImageView matchIcon = (ImageView) convertView.findViewById(R.id.matchIcon); int iCompatibility = user.optInt("iCompatibility"); if (iCompatibility != 0) { userMatch.setText( iCompatibility + "%"); } else { userMatch.setVisibility(TextView.INVISIBLE); matchIcon.setVisibility(ImageView.INVISIBLE); } ImageView userIcon = (ImageView) convertView.findViewById(R.id.userIcon); String sUserIcon = user.optString("sImageUrl-thumb"); imageLoader.DisplayImage(sUserIcon, Users.this, userIcon); return convertView; } }
I am rather puzzled by why the click listener is not working. This code works in many other places for me.
source share