So I'm working on an app and I have a button in which the user clicks to cycle through three ordering sets for an array list. I have it where Collections.sort(list) sorts the list numerically and alphabetically, but I'm trying to make it where listis sorted by either index number or time added.
Here's what I have:
public class MainActivity extends Activity
{
ArrayList<String> list;
ArrayAdapter adapter;
ListView listView;
public int counter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list = new ArrayList<>();
listView = findViewById(R.id.listView);
adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,list);
listView.setAdapter(adapter);
addEntries();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
{
}
});
}
public void addEntries(){
for(int e=0; e<=10; e++){
list.add(String.valueOf(e));
}
adapter.notifyDataSetChanged();
}
public void sort(View v){
counter = counter + 1;
if(counter == 2){
counter = 0;
}
switch(counter){
case 0:Collections.sort(list);
message("0");
break;
case 1://code to sort by time/index;
message("1");
break;
}
adapter.notifyDataSetChanged();
}
public void message(String message){
Toast.makeText(getApplicationContext(),message,Toast.LENGTH_SHORT).show();
}
}