我无法按字母顺序排列可扩展列表的标题。我从我的数据库中获取列表的标题。我从数据库按字母顺序排序,但是当我将它们添加到我的可扩展列表时会发生一些事情,因为当我测试它(在我的手机上)时,它们看起来没有顺序。你能帮忙吗?
HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();
(...)
List<String> categoria_header = new ArrayList<String>();
Database db = new Database(context);
List<Categorias> categorias;
categorias = db.getAllCategorias();
for (int i=0; i<categorias.size(); i++){
//Log.d("Expandabe","-->"+categorias.get(i).toString());
expandableListDetail.put(categorias.get(i).toString(), categoria_header);
}
然后我的getAllCategories方法是:
public List<Categorias> getAllCategorias(){
String selectQuery;
Cursor cursor;
int i=0;
List<Categorias> categorias = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
selectQuery = "SELECT * FROM " + TABLE_CATEGORIA + " ORDER BY " + col_NOME_CATEGORIA + " ASC;";
//Log.d("Database-->",""+selectQuery);
cursor = db.rawQuery(selectQuery, null);
if (cursor !=null) {
while (cursor.moveToNext()) {
Categorias categoria = new Categorias();
categoria.setNomeCategoria(cursor.getString(cursor.getColumnIndex(col_NOME_CATEGORIA)));
categorias.add(categoria);
}
}
db.close();
return categorias;
}
感谢。
答案 0 :(得分:0)
这是因为您的可展开列表是./script.sh "tmp.txt" "/project"
echo $1 = tmp.txt
echo $2 = /project
$1 - file name
$2 - directory
if [ -f $2/$1 ] - checks if file exists, -f for files, -d for directory
cp $1 $2/$1 - copy file to directory/file_name
if [ -f /project/tmp.txt ]
cp tmp.txt /project/tmp.txt
。
HashMaps是无序的,即当您迭代它时,保证HashMap<String, List<String>> expandableListDetail
对的顺序不保证是相同的。
在您的方案中,您需要K,V
,这将保留LinkedHashMap
对的顺序。