how can i do table view?
I want left click on latency and sort by latency. Or left click on players sort by players ascend.
I did a lot of research on the internet. But I could not find an easy and convenient TableView.
I want, Example:
tableview.addElement(“server name”,“players”,“map”,“latency”…);
and
tableview.setOnClickListener()
highlight in row
and
tableview.setOnRightClickListener()
openPopupMenu()
How can I do the easiest thing like that?
Hello
For the sorting of different things as Server Name, Player Count, Map, etc. If you have each tabs information stored as a List, they have an easy function called Sort();
Example
public List<TabInformation> tabInformationList; //This list will hold all the tabs in the table.
private struct TabInformation
{
public string serverName;
public int playerCount;
public int latency;
}
private enum SortMode
{
None,
ServerName,
PlayerCount,
Latency
}
public void SortTabList(SortMode mode)
{
switch(mode)
{
case mode.ServerName:
tabInformationList.Sort(SortByName);
break;
case mode.PlayerCount:
tabInformationList.Sort(SortByPlayers);
break;
case mode.Latency:
tabInformationList.Sort(SortByLatency);
break;
}
//Then just refresh the list, and replace each tab according to the new list.
}
private int SortByName(TabInformation i1, TabInformation i2)
{
return i1.serverName.CompareTo(i2.serverName);
}
private int SortByPlayers(TabInformation i1, TabInformation i2)
{
return i1.playerCount.CompareTo(i2.playerCount)
}
private int SortByLatency(TabInformation i1, TabInformation i2)
{
return i1.latency.CompareTo(i2.latency);
}
I would use something like this, if it was up to me. For the rest part, by clicking and adding stuff, place a script on each tab, which also might make it easy to manipulate them and get their information. I hope this helps some, otherwise feel free to always ask.
As for adding more, have an item as a prefabrication which you always can instantiate, then have a function called something like EstablishList(string name, int playerCount, int latency). Which will handle displaying the right information.
Regards