ListView的项目重新排序 [英] ListView Reorder Items
问题描述
我试图寻找答案,但我找不到任何。
I tried to look answers but I couldn't find any.
所以我要改变我的ListView项目订购应用程序,我没有任何想法如何做到这一点。我想拖放太辛苦建立但如何对一些箭头按钮,您可以在preSS和项目移动一行吗?如何使应用程序记住它们的顺序下一次我打开它的每一个项目都是为了在那里我感动他们?
So I want to change my ListView items order in app and I don't have any idea how to do that. I guess Drag and Drop is too hard to build but how about some arrow buttons where you can press up and item move one row up? And how to make app to remember order that next time I open it every item are in order where I moved them?
我有我的ListView项目在自己的文件(值时─> arrays.xml)。这里是我的ListView活动:
I have my ListView Items in their own file (values->arrays.xml). And here is my ListView activity:
public class MainScreen extends ListActivity implements OnClickListener{
/** Called when the activity is first created. **/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String[] links = getResources().getStringArray(R.array.links);
setListAdapter(ArrayAdapter.createFromResource(getApplicationContext(),
R.array.items, R.layout.rowlayout));
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String content = links[position];
Intent showContent = new Intent(getApplicationContext(),
Web.class);
showContent.setData(Uri.parse(content));
startActivity(showContent);
}
});
}
}
任何人有知道如何使它发挥作用? :)
Anyone have idea how to make it work? :)
推荐答案
据我所知,<一个href=\"http://stackoverflow.com/questions/2069671/how-to-change-string-resource-xml-values-in-android-programatically\">String资源是静态的,所以你不能操纵在code中的XML (改变顺序,添加/删除项目...等)。
As far as I know, String resources are static so you cannot manipulate the xml in the code (to change the order, add / remove items ..etc).
不过,我能想到您的问题两个解决方案。
But I can think of two solutions for your problem.
-
保存rel=\"nofollow\">共享$您在与它应用到你的
的String []
的的onCreate()
(如保存您的字符串数组index--令人毛骨悚然,但顺序会的工作,我认为)
Save the order you want in the SharedPreferences and apply it to your
String[]
in theonCreate()
(e.g. save the sequence of your string array index-- creepy but would work, I think)
了解并开始使用 SqlLite 的数据库,如果这正是你要设法避免:)
Learn and start using a SqlLite database if that s what you are trying to avoid :)
修改
要了解如何使用共享preferences:这里检查code段的 http://developer.android.com/guide/topics/data/data-storage.html
To see how to use SharedPreferences : check the code snippet here http://developer.android.com/guide/topics/data/data-storage.html
这篇关于ListView的项目重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!