title: How to set listview row clickable only one time in android?
body: <p>Explanation:
             I have a listview in my fragment. When I click one of the row of the listview it goes to another activity.In listview,I got the data from the adapter.
  Inside the adapter view,I set the setOnClick().</p>
  
  <p>Problem is when I click one of the row multiple time it is opening multiple activity.I want to restrict only one time click on the particular row over the listview item.</p>
  
  <p>Here is my fragment where I get the listview and set the adapter-</p>
  
  <pre><code>public class HomeFragment extends Fragment{
      public HomeFragment() {
      }
  
      public static String key_updated = "updated", key_description = "description", key_title = "title", key_link = "link", key_url = "url", key_name = "name", key_description_text = "description_text";
      private static String url = "";
  
      List&lt;String&gt; lst_key = null;
      List&lt;JSONObject&gt; arr_completed = null;
      List&lt;String&gt; lst_key2 = null;
  
      List&lt;JSONObject&gt; lst_obj = null;
      List&lt;String&gt; list_status = null;
      ListView completed_listview;
      int PagerLength = 0,exeption_flag=0;
  
      View rootView;
      private ViewPager pagerRecentMatches;
      private ImageView imgOneSliderRecent;
      private ImageView imgTwoSliderRecent;
      private ImageView imgThreeSliderRecent;
      private ImageView imgFourSliderRecent;
      private ImageView imgFiveSliderRecent;
      private ImageView imgSixSliderRecent;
      private ImageView imgSevenSliderRecent;
      private ImageView imgEightSliderRecent;
  
      LinearLayout selector_dynamic;
      LinearLayout Recent_header_layout;
      FrameLayout adbar;
      String access_token = "";
      SharedPreferences sharedPreferences;
      int current_pos=0,status_flag=0;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setHasOptionsMenu(false);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          rootView = inflater.inflate(R.layout.fragment_home, container, false);
          findViews();
  
          selector_dynamic = (LinearLayout) rootView.findViewById(R.id.selectors_dynamic);
          adbar = (FrameLayout) rootView.findViewById(R.id.adbar);
          new AddLoader(getContext()).LoadAds(adbar);
  
          MainActivity activity = (MainActivity) getActivity();
          access_token = activity.getMyData();
  
          sharedPreferences = getContext().getSharedPreferences("HomePref", Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
  
          if (access_token == null || access_token=="") {
              url = "https://api.litzscore.com/rest/v2/recent_matches/?access_token=" + sharedPreferences.getString("access_token", null) + "&amp;card_type=summary_card";
  
          } else {
              editor.putString("access_token", access_token);
              editor.commit();
              url = "https://api.litzscore.com/rest/v2/recent_matches/?access_token=" + access_token + "&amp;card_type=summary_card";
          }
          completed_listview = (ListView) rootView.findViewById(R.id.completed_listview);
  
  
          Recent_header_layout = (LinearLayout) rootView.findViewById(R.id.Recent_header_layout);
  
          Recent_header_layout.setVisibility(View.GONE);
  
          if(!Utils.isNetworkConnected(getContext())){
              dialog_popup();
          }
          else{
              new TabJson().execute();
          }
          pagerRecentMatches.setOnTouchListener(new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  return false;
              }
          });
  
          return rootView;
      }
  
      @Override
      public void onPrepareOptionsMenu(Menu menu) {
          super.onPrepareOptionsMenu(menu);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          return super.onOptionsItemSelected(item);
      }
  
      private void dialog_popup() {
          final Dialog dialog = new Dialog(getContext());
          DisplayMetrics metrics = getResources()
                  .getDisplayMetrics();
          int screenWidth = (int) (metrics.widthPixels * 0.90);
          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
          dialog.setContentView(R.layout.internet_alert_box);
          dialog.getWindow().setLayout(screenWidth, WindowManager.LayoutParams.WRAP_CONTENT);
          dialog.setCancelable(true);
  
          Button btnNo = (Button) dialog.findViewById(R.id.btn_no);
          Button btnYes = (Button) dialog.findViewById(R.id.btn_yes);
  
          btnNo.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  dialog.dismiss();
                  getActivity().finish();
              }
          });
          dialog.show();
          btnYes.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if(!Utils.isNetworkConnected(getContext())){
                      dialog_popup();
                  }
                  else{
                      dialog.dismiss();
                      new TabJson().execute();
                  }
              }
          });
          dialog.show();
      }
      public class TabJson extends AsyncTask&lt;String, String, String&gt; {
  
          String jsonStr = "";
  
          @Override
          protected void onPreExecute() {
              Utils.Pdialog(getContext());
          }
  
          @Override
          protected String doInBackground(String... params) {
  
              jsonStr = new CallAPI().GetResponseGetMethod(url);
              exeption_flag=0;
              status_flag = 0;
              if (jsonStr != null) {
                  try {
                      if (jsonStr.equals("IO") || jsonStr.equals("MalFormed") || jsonStr.equals("NotResponse")) {
                          exeption_flag = 1;
                      } else {
                          JSONObject obj = new JSONObject(jsonStr);
  
                          if (obj.has("status") &amp;&amp; !obj.isNull("status")) {
                              if (obj.getString("status").equals("false") || obj.getString("status").equals("403")) {
                                  status_flag = 1;
                              } else {
                                  JSONObject data = obj.getJSONObject("data");
                                  JSONArray card = data.getJSONArray("cards");
  
                                  PagerLength = 0;
                                  lst_obj = new ArrayList&lt;&gt;();
                                  list_status = new ArrayList&lt;&gt;();
                                  lst_key = new ArrayList&lt;&gt;();
                                  lst_key2 = new ArrayList&lt;&gt;();
  
                                  arr_completed = new ArrayList&lt;&gt;();
                                  for (int i = 0; i &lt; card.length(); i++) {
                                      JSONObject card_obj = card.getJSONObject(i);
                                      if (card_obj.getString("status").equals("started")) {
                                          PagerLength++;
                                          lst_obj.add(card_obj);
                                          list_status.add(card_obj.getString("status"));
                                          lst_key.add(card_obj.getString("key"));
                                      }
                                      if (card_obj.getString("status").equals("notstarted")) {
                                          PagerLength++;
                                          lst_obj.add(card_obj);
                                          list_status.add(card_obj.getString("status"));
                                          lst_key.add(card_obj.getString("key"));
                                      }
                                      if (card_obj.getString("status").equals("completed")) {
                                          arr_completed.add(card_obj);
                                          lst_key2.add(card_obj.getString("key"));
                                      }
                                  }
                              }
                          }
                      }
                  }
                  catch(JSONException e){
                      e.printStackTrace();
                  }
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(String s) {
              super.onPostExecute(s);
              Utils.Pdialog_dismiss();
  
              if (status_flag == 1 || exeption_flag==1) {
                  dialog_popup();
              } else {
                  Recent_header_layout.setVisibility(View.VISIBLE);
  
                  LiveAdapter adapterTabRecent = new LiveAdapter(getContext(), lst_obj, PagerLength, list_status, lst_key);
                  adapterTabRecent.notifyDataSetChanged();
                  pagerRecentMatches.setAdapter(adapterTabRecent);
                  pagerRecentMatches.setCurrentItem(current_pos);
  
  
                  ScheduleAdapter CmAdapter = new ScheduleAdapter(getContext(), arr_completed, lst_key2);
                  CmAdapter.notifyDataSetChanged();
                  completed_listview.setAdapter(CmAdapter);
              }
          }
      }
  
      private void findViews() {
  
          pagerRecentMatches = (ViewPager) rootView
                  .findViewById(R.id.pager_recent_matches);
          imgOneSliderRecent = (ImageView) rootView
                  .findViewById(R.id.img_one_slider_recent);
          imgTwoSliderRecent = (ImageView) rootView
                  .findViewById(R.id.img_two_slider_recent);
          imgThreeSliderRecent = (ImageView) rootView
                  .findViewById(R.id.img_three_slider_recent);
          imgFourSliderRecent=(ImageView)rootView.findViewById(R.id.img_four_slider_recent);
          imgFiveSliderRecent=(ImageView)rootView.findViewById(R.id.img_five_slider_recent);
          imgSixSliderRecent=(ImageView)rootView.findViewById(R.id.img_six_slider_recent);
          imgSevenSliderRecent = (ImageView) rootView.findViewById(R.id.img_seven_slider_recent);
          imgEightSliderRecent = (ImageView) rootView.findViewById(R.id.img_eight_slider_recent);
      }
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
      }
  
  }
  </code></pre>
  
  <p>After load the data from the server it passed to the onPost() i called an adapter which extends BaseAdpter</p>
  
  <p>Here is my BaseAdapter </p>
  
  <p>package adapter;</p>
  
  <pre><code>public class ScheduleAdapter extends BaseAdapter{
  
      private Context context;
      private List&lt;JSONObject&gt; arr_schedule;
      private List&lt;String&gt; arr_matchKey;
      private static LayoutInflater inflater;
      int flag = 0;
      String time="";
      String status="";
      String match_title = "";
      String match_key="";
  
      public ScheduleAdapter(Context context,List&lt;JSONObject&gt; arr_schedule,List&lt;String&gt; arr_matchKey){
          this.context=context;
          this.arr_schedule=arr_schedule;
          this.arr_matchKey=arr_matchKey;
          inflater=(LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      @Override
      public int getCount() {
          return this.arr_schedule.size();
      }
  
      @Override
      public Object getItem(int position) {
          return this.arr_schedule.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      private class Holder{
          TextView txt_one_country_name;
          TextView txt_two_country_name;
          TextView txt_venue;
          TextView txtTimeGMT;
          TextView txtDate;
          TextView txtTimeIST;
          ImageView team_one_flag_icon;
          ImageView team_two_flag_icon;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
  
          Holder holder=new Holder();
          String[] parts;
          String[] state_parts;
          String[] match_parts;
          Typeface tf=null;
          String winner_team = "";
          String final_Score="";
          String now_bat_team="",team_name="";
          String related_status="";
  
          if(convertView==null) {
  
              convertView = inflater.inflate(R.layout.recent_home_layout, null);
  
              holder.txt_one_country_name = (TextView) convertView.findViewById(R.id.txt_one_country_name);
              holder.txt_two_country_name = (TextView) convertView.findViewById(R.id.txt_two_country_name);
              holder.txt_venue = (TextView) convertView.findViewById(R.id.venue);
              holder.txtTimeIST = (TextView) convertView.findViewById(R.id.txt_timeist);
              holder.txtTimeGMT = (TextView) convertView.findViewById(R.id.txt_timegmt);
              holder.txtDate = (TextView) convertView.findViewById(R.id.txt_date);
              holder.team_one_flag_icon = (ImageView) convertView.findViewById(R.id.team_one_flag_icon);
              holder.team_two_flag_icon = (ImageView) convertView.findViewById(R.id.team_two_flag_icon);
  
              tf = Typeface.createFromAsset(convertView.getResources().getAssets(), "Roboto-Regular.ttf");
  
              holder.txt_one_country_name.setTypeface(tf);
              holder.txt_two_country_name.setTypeface(tf);
              holder.txt_venue.setTypeface(tf);
              holder.txtTimeIST.setTypeface(tf);
              holder.txtTimeGMT.setTypeface(tf);
              holder.txtDate.setTypeface(tf);
  
              convertView.setTag(holder);
          }
          else{
              holder=(Holder)convertView.getTag();
          }
  
          try {
              String overs="";
              String wickets_now="";
              String now_runs="";
              String[] over_parts;
  
              time = "";
              JSONObject mainObj = this.arr_schedule.get(position);
  
              status = mainObj.getString("status");
  
              String name = mainObj.getString("short_name");
              String state = mainObj.getString("venue");
              String title = mainObj.getString("title");
              related_status=mainObj.getString("related_name");
  
              JSONObject start_date = mainObj.getJSONObject("start_date");
  
  
              JSONObject teams=null;
              JSONObject team_a=null;
              JSONObject team_b=null;
              String team_a_key="";
              String team_b_key="";
              time = start_date.getString("iso");
  
              parts = name.split("vs");
              match_parts = title.split("-");
              state_parts = state.split(",");
  
              int length = state_parts.length;
  
              flag=0;
              match_title="";
              winner_team="";
  
              if (!mainObj.isNull("msgs")) {
                  JSONObject msgs = mainObj.getJSONObject("msgs");
                  winner_team = "";
                  if (msgs.has("info")) {
                      winner_team = msgs.getString("info");
                      flag = 1;
                  }
              }
  
              match_title=name+" - "+match_parts[1];
  
              JSONObject now=null;
              if(mainObj.has("now") &amp;&amp; !mainObj.isNull("now")) {
                  now = mainObj.getJSONObject("now");
                  if (now.has("batting_team")) {
                      now_bat_team = now.getString("batting_team");
                  }
                  if (now.has("runs")) {
                      if (now.getString("runs").equals("0")) {
                          now_runs = "0";
                      } else {
                          now_runs = now.getString("runs");
                      }
                  }
  
                  if (now.has("runs_str") &amp;&amp; !now.isNull("runs_str")) {
                      if (now.getString("runs_str").equals("0")) {
                          overs = "0";
                      } else {
                          if(now.getString("runs_str").equals("null")){
                              overs="0";
                          }
                          else{
                              over_parts=now.getString("runs_str").split(" ");
                              overs=over_parts[2];
                          }
                      }
                  }
                  if (now.has("wicket")) {
                      if (now.getString("wicket").equals("0")) {
                          wickets_now = "0";
                      } else {
                          wickets_now = now.getString("wicket");
                      }
                  }
              }
              try {
                  if (!mainObj.isNull("teams") &amp;&amp; mainObj.has("teams")) {
                      teams = mainObj.getJSONObject("teams");
                      team_a = teams.getJSONObject("a");
                      team_b = teams.getJSONObject("b");
                      team_a_key = team_a.getString("key");
                      team_b_key = team_b.getString("key");
  
                      JSONArray team_arr = teams.names();
                      JSONObject team_obj;
                      for (int a = 0; a &lt; team_arr.length(); a++) {
                          if (now_bat_team.equals(team_arr.getString(a))) {
                              team_obj = teams.getJSONObject(team_arr.getString(a));
                              if (team_obj.has("short_name") &amp;&amp; !team_obj.isNull("short_name")) {
                                  team_name = team_obj.getString("short_name");
                              }
                          }
                      }
                  }
              }
              catch (NullPointerException e){
                  e.printStackTrace();
              }
  
              if(mainObj.has("status_overview") &amp;&amp; !mainObj.isNull("status_overview")){
                  if(mainObj.getString("status_overview").equals("abandoned") || mainObj.getString("status_overview").equals("canceled")){
                      final_Score="";
                  }
                  else{
                      final_Score=team_name+" - "+now_runs+"/"+wickets_now+" ("+overs+" ovr)";
                  }
              }
  
              holder.txt_one_country_name.setText(parts[0]);
              holder.txt_two_country_name.setText(parts[1]);
  
              if(length==1){
                  holder.txtTimeGMT.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
                  holder.txtTimeGMT.setText(state_parts[0]);
              }
              if(length==2){
                  holder.txtTimeGMT.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
                  holder.txtTimeGMT.setText(state_parts[0] + "," + state_parts[1]);
  
              }
              if(length==3){
                  holder.txtTimeGMT.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
                  holder.txtTimeGMT.setText(state_parts[1] + "," + state_parts[2]);
              }
              if(length==4){
                  holder.txtTimeGMT.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
                  holder.txtTimeGMT.setText(state_parts[2] + "," + state_parts[3]);
              }
  
              holder.txtDate.setText(final_Score);
              holder.txtDate.setTypeface(tf, Typeface.BOLD);
              holder.txtDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
              holder.txtTimeIST.setText(winner_team);
              holder.txt_venue.setText(related_status);
          } catch (JSONException e) {
              e.printStackTrace();
          }
          convertView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  match_key = arr_matchKey.get(position);
                  MainActivity activity = (MainActivity) context;
                  GetValue gv = new GetValue(context);
                  gv.setFullUrl(match_key);
                  gv.setAccessToken(activity.getMyData());
                  gv.execute();
              }
          });
  
          return convertView;
      }
  
      @Override
      public boolean isEnabled(int position) {
          return super.isEnabled(position);
      }
  }
  </code></pre>
  
  <p>This adapter set the listrow item into listview.</p>
  
  <p>In ScheduleAdapter.java i set the onclick() on the convertView in which i called a GetValue class which is only implement a Asynctask to get the data and called and intent then it goes to an activity.</p>
  
  <p>Means HomeFragment->ScheduleAdapter->GetValue->Scorecard</p>
  
  <p>Here,
      HomeFragment is fragment which have listview</p>
  
  <p>ScheduleAdpter is an adapter which set data to listview which reside in homefragment</p>
  
  <p>GetValue is class which implement some important task and it passed an intent and goes to an activity(It's work as a background)</p>
  
  <p>ScoreCard is my activity which called after click on the row of the listview which reside in HomeFragment.</p>
  
  <p>Please, help me to solve out this problem.</p>