我有一个RecyclerView显示一些数据,具体取决于用户搜索的内容。当用户点击其中一个项目时,它会启动一个新的意图,其中包含有关他点击的项目的更多信息。在第一次搜索中它工作正常但是当我清除recyclerview并添加新项目时,五个第一项启动意图两次,而其余5个启动它一次(应该发生什么)
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 :(得分:0)
通过再次设置适配器来修复它,以便更新RecyclerView数据。