2016-12-25 70 views
1

我有一個RecyclerView顯示一些數據,具體取決於用戶搜索的內容。當用戶點擊其中一個項目時,它會啓動一個新的目標,並提供有關他點擊的項目的更多信息。第一搜索它工作正常,但是當我清除recyclerview,並添加新項目,則五個第一項發起的意圖兩倍,而5發佈一次(什麼是應該發生的)RecyclerView在添加新項目後點擊兩次

MatchListCustomAdapter.cs其餘

private void MMainView_Click(object sender, EventArgs e) 
     { 
      int position = mRecyclerView.GetChildLayoutPosition((View)sender); 


      mainAct.launchActivity(mgame[position].Id); 
     } 

MainActivity.cs

private void function1() 
     { 
      //Clears the list at the beginning and each time a new user is queried so it doesn't add more than 10 games. 
      game.Clear(); 
      mAdapter.NotifyDataSetChanged(); 
      System.Diagnostics.Debug.WriteLine("This is from the recentgamesdoworkcompleted"); 
      for (int i = 0; i < 10; i++) 
      { 
       //This sets the color of the listview depending if it's a victory or defeat. 
       if (mclass.win[i]) 
       { 
        winorlose = Color.ParseColor("#42A5F5"); 
       } 
       else 
       { 
        winorlose = Color.ParseColor("#D32F2F"); 

       } 
       game.Add(new Models.MatchHistoryListView() 
       { 
        Name = "" + mclass.summonerId[0, i], 
        ChampionId = mclass.championId[0, i], 
        Id = mclass.recentGamesId[i], 
        Score = mclass.summonerScoreText[i], 
        championPortraito = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/champion/" + mclass.championName[0, i] + ".png"), 
        Item0 = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/item/" + mclass.summonerItems[i, 0] + ".png"), 
        Item1 = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/item/" + mclass.summonerItems[i, 1] + ".png"), 
        Item2 = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/item/" + mclass.summonerItems[i, 2] + ".png"), 
        Item3 = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/item/" + mclass.summonerItems[i, 3] + ".png"), 
        Item4 = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/item/" + mclass.summonerItems[i, 4] + ".png"), 
        Item5 = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/item/" + mclass.summonerItems[i, 5] + ".png"), 
        Item6 = new Uri("http://ddragon.leagueoflegends.com/cdn/6.24.1/img/item/" + mclass.summonerItems[i, 6] + ".png"), 
        listViewColor = winorlose 

       }); 

      } 
     } 

回答

0

通過再次設置適配器來修復它,這是RecyclerView數據更新的時間。

相關問題