title: Use CustomAdapter and OnItenClickListener. Listener is not responding
body: <p>Here is my code.</p>
  
  <p>I try to add OnItenClickListener to "lastCommand" listView but it is not responde. Any errors at compile.</p>
  
  <pre><code>package pl.globoox.sprawdzsprzedawce;
  
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.design.widget.NavigationView;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.ListView;
  import android.widget.SearchView;
  import android.widget.TextView;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.toolbox.Volley;
  import com.facebook.CallbackManager;
  import com.facebook.FacebookCallback;
  import com.facebook.FacebookException;
  import com.facebook.FacebookSdk;
  import com.facebook.GraphRequest;
  import com.facebook.GraphResponse;
  import com.facebook.login.LoginManager;
  import com.facebook.login.LoginResult;
  import com.facebook.login.widget.LoginButton;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  
  import pl.globoox.sprawdzsprzedawce.Utils.LastCommentHome;
  import pl.globoox.sprawdzsprzedawce.Utils.QueryCheck;
  
  import static pl.globoox.sprawdzsprzedawce.R.id.buttonCheckButton;
  
  public class MainActivity extends AppCompatActivity
          implements NavigationView.OnNavigationItemSelectedListener {
  
  
      ListView lastComments;
      LoginButton loginButton;
      CallbackManager callbackManager;
      ArrayList&lt;String&gt; comments_userList = new ArrayList();
      ArrayList&lt;String&gt; comments_olxUserList = new ArrayList();
      ArrayList&lt;String&gt; comments_dateList = new ArrayList();
      ArrayList&lt;String&gt; comments_messageList = new ArrayList();
      ArrayList&lt;String&gt; comments_statusList = new ArrayList();
  
      ImageView imageViewFBUser;
      TextView textViewFBName;
      TextView textViewFBEmail;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          FacebookSdk.sdkInitialize(getApplicationContext());
          setContentView(R.layout.activity_main);
          initializeControls();
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          loginWithFb();
  
  
          // MENU DRAWER
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                  this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
          drawer.addDrawerListener(toggle);
          toggle.syncState();
  
          NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
          navigationView.setNavigationItemSelectedListener(this);
          View headerView = navigationView.getHeaderView(0);
  
          textViewFBName = headerView.findViewById(R.id.textViewFBName);
          textViewFBEmail = headerView.findViewById(R.id.textViewFBEmail);
          imageViewFBUser = headerView.findViewById(R.id.imageViewFBUser);
  
          imageViewFBUser.setVisibility(View.INVISIBLE);
          textViewFBName.setText("");
          textViewFBEmail.setText("");
  
  
          // MAIN CONTENT APP
          final SearchView editTextOfferLink = (SearchView) findViewById(R.id.editTextOfferLink);
          final Button buttonCheck = (Button) findViewById(buttonCheckButton);
          lastComments = (ListView) findViewById(R.id.listViewLastComments);
  
  
  
          buttonCheck.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  final String offerLink = editTextOfferLink.getQuery().toString();
                  boolean error = false;
  
                  // CHECK FORM EMPTY
                  if (offerLink.isEmpty()) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                      builder.setMessage(R.string.formEmpty).setNegativeButton(R.string.tryAgain, null).create().show();
                      error = true;
                      return;
                  }
  
                  if (error == false) {
                      Response.Listener&lt;String&gt; responseListener = new Response.Listener&lt;String&gt;() {
                          @Override
                          public void onResponse(String response) {
                              try {
                                  JSONObject jsonResponse = new JSONObject(response);
                                  int errorCode = jsonResponse.getInt("errorCode");
                                  String userID = jsonResponse.getString("userID");
  
                                  // CANT CONNECT TO DATABASE
                                  if (errorCode == 1) {
                                      AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                                      builder.setMessage(R.string.cantConnectToDatabase).setNegativeButton(R.string.tryAgain, null).create().show();
                                  }
  
                                  // USER NOT FOUND
                                  else if (errorCode == 2) {
                                      Boolean isBank = jsonResponse.getBoolean("isBank");
                                      Intent i;
                                      i = new Intent(getApplicationContext(), AddNewUserActivity.class);
                                      if (isBank == true) {
                                          i.putExtra("isBank", "true");
                                      } else {
                                          i.putExtra("isBank", "false");
                                      }
                                      String userName = jsonResponse.getString("userName");
                                      String registerDate = jsonResponse.getString("registerDate");
                                      i.putExtra("userID", userID);
                                      i.putExtra("userName", userName);
                                      i.putExtra("registerDate", registerDate);
                                      finish();
                                      startActivity(i);
                                  }
  
                                  // EMPTY OFFER VARIABLE
                                  else if (errorCode == 3) {
                                      AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                                      builder.setMessage(R.string.omptyOfferVariable).setNegativeButton(R.string.tryAgain, null).create().show();
                                  }
  
                                  // BAD LINK
                                  else if (errorCode == 4) {
                                      AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                                      builder.setMessage(R.string.badOfferLink).setNegativeButton(R.string.tryAgain, null).create().show();
                                  }
  
                                  // USER FOUND!
                                  else if (errorCode == 5) {
                                      Boolean isBank = jsonResponse.getBoolean("isBank");
                                      Intent i;
                                      i = new Intent(getApplicationContext(), UserAreaActivity.class);
                                      i.putExtra("userID", userID);
                                      i.putExtra("isBank", isBank.toString());
                                      finish();
                                      startActivity(i);
                                  }
  
                              } catch (JSONException e) {
                                  e.printStackTrace();
                              }
                          }
  
                      };
  
                      QueryCheck offerQueryRequest = new QueryCheck(offerLink, responseListener);
                      RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
                      queue.add(offerQueryRequest);
                  }
  
              }
          });
  
          // LAST COMMENTS SHOW
          Response.Listener&lt;String&gt; responseListenerLastComments = new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  try {
                      JSONObject jsonResponse = new JSONObject(response);
                      int errorCode = jsonResponse.getInt("errorCode");
                      int count = jsonResponse.getInt("count");
                      Log.d("Tag", String.valueOf(errorCode));
  
                      JSONArray commentsArray = jsonResponse.getJSONArray("comments");
                      Log.d("TAG", String.valueOf(commentsArray));
  
                      for (int i = 0; i &lt; count; i++) {
                          JSONObject jsonObject = commentsArray.getJSONObject(i);
                          comments_userList.add(jsonObject.getString("user"));
                          comments_olxUserList.add(jsonObject.getString("olxUser"));
                          comments_dateList.add(jsonObject.getString("date"));
                          comments_messageList.add(jsonObject.getString("message"));
                          comments_statusList.add(jsonObject.getString("status"));
                      }
  
                      MainActivity.CustomAdapter customAdapter = new MainActivity.CustomAdapter();
                      lastComments.setAdapter(customAdapter);
  
  
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
              }
          };
  
  
  
          LastCommentHome lastCommentHome = new LastCommentHome("3", responseListenerLastComments);
          RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
          queue.add(lastCommentHome);
  
  
     }
  
  
  
  
  
  
  
      private void loginWithFb() {
          // LOGIN MANAGER FACEBOOK
          LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback&lt;LoginResult&gt;() {
              @Override
              public void onSuccess(LoginResult loginResult) {
                  GraphRequest.newMeRequest(
                          loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                              @Override
                              public void onCompleted(JSONObject me, GraphResponse response) {
                                  if (response.getError() != null) {
                                      // handle error
                                  } else {
                                      String email = me.optString("email");
                                      String name = me.optString("name");
                                      String picture = me.optString("picture");
                                      imageViewFBUser.setVisibility(View.VISIBLE);
                                      imageViewFBUser.setImageURI(Uri.parse(picture));
                                      textViewFBName.setText(name);
                                      textViewFBEmail.setText(email);
                                  }
                              }
                          }).executeAsync();
              }
  
              @Override
              public void onCancel() {
                  textViewFBName.setText("Login canceled!");
              }
  
              @Override
              public void onError(FacebookException error) {
                  textViewFBName.setText("Login error: " + error.getMessage());
              }
          });
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          callbackManager.onActivityResult(requestCode, resultCode, data);
          super.onActivityResult(requestCode, resultCode, data);
      }
  
  
      // FACEBOOK INITALZIZE LOGIN
      private void initializeControls() {
          callbackManager = CallbackManager.Factory.create();
          loginButton = findViewById(R.id.login_button);
      }
  
      @Override
      public void onBackPressed() {
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          if (drawer.isDrawerOpen(GravityCompat.START)) {
              drawer.closeDrawer(GravityCompat.START);
          } else {
              super.onBackPressed();
          }
      }
  
  
      @SuppressWarnings("StatementWithEmptyBody")
      @Override
      public boolean onNavigationItemSelected(MenuItem item) {
          // Handle navigation view item clicks here.
          int id = item.getItemId();
  
          if (id == R.id.nav_search) {
              // Handle the camera action
          } else if (id == R.id.nav_best) {
  
          } else if (id == R.id.nav_worst) {
  
          } else if (id == R.id.nav_comments) {
  
          } else if (id == R.id.nav_policy) {
  
          } else if (id == R.id.nav_rules) {
  
          } else if (id == R.id.nav_about) {
  
          } else if (id == R.id.nav_contact) {
  
          }
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          drawer.closeDrawer(GravityCompat.START);
          return true;
      }
  
  
      class CustomAdapter extends BaseAdapter {
  
          @Override
          public int getCount() {
              return comments_dateList.size();
          }
  
          @Override
          public Object getItem(int position) {
              return null;
          }
  
          @Override
          public long getItemId(int position) {
              return 0;
          }
  
          @Override
          public boolean isEnabled(int position) {
              return false;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              convertView = getLayoutInflater().inflate(R.layout.customlayout_lastcomment_homepage, null);
              TextView textViewUser = (TextView) convertView.findViewById(R.id.textViewUser);
              TextView textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
              TextView textViewMessage = (TextView) convertView.findViewById(R.id.textViewMessage);
              textViewUser.setText(comments_userList.get(position));
              textViewDate.setText(comments_dateList.get(position));
              textViewMessage.setText(comments_messageList.get(position));
  
              lastComments.setOnItemClickListener(new AdapterView.OnItemClickListener(){
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent,
                                          View view, int position, long id) {
                      Log.d("asdasdxxxxx", String.valueOf(position));
                  }});
  
  
  
  
              return convertView;
          }
  
      }
  
  
  }
  </code></pre>