Rails 3,国际化(I18n) - 将数字转换为值(Rails 3, Internationalization (I18n) - Translate number to value)
我有一个带有级别列的用户表。 level列是数字,值为0,1或2。
反正有没有得到国际化(I18n)API来转换数值,所以在英语0 = Foobar,1 = Foo,2 = Bar? 然后在另一种语言0,1,2可以返回别的东西?
谢谢
I have a user table with a level column. The level column is numeric and the value is 0, 1, or 2.
Is there anyway to get the Internationalization (I18n) API to convert the numeric value so that in english 0 = Foobar, 1 = Foo, 2 = Bar? Then in another language 0,1,2 could return something else?
Thanks
原文:https://stackoverflow.com/questions/6202603
最满意答案
好的,我找到了一个很好的解决方案:OnScrollListener提供了我所需要的一切,而这里不需要OnGlobalLayoutListener。
public class ArrayListAdapter extends ArrayAdapter<String> implements AbsListView.OnScrollListener ... @Override public void onScrollStateChanged(AbsListView view, int scrollState) {} @Override public synchronized void onScroll(final AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { List<Integer>yList = new ArrayList<>(); int checkedPosition = listView.getCheckedItemPosition(); double yChecked = 0; for (int pos = 0; pos < totalItemCount; pos++) { CheckedTextView tv = (CheckedTextView) this .getViewByPosition(pos, listView, firstVisibleItem, firstVisibleItem + visibleItemCount - 1); if (pos == checkedPosition) { yChecked = tv.getY(); } yList.add(pos, tv.getY()); } // Here I pass the fresh y-values to the fragment holding the // two ListViews. After some further calculations the fragment // passes the data to the TextView where it is stored and // this.invalidate is called to eventually trigger the onDraw method. originalFragment.setScrollData(yList, yChecked); } private View getViewByPosition(int pos, AbsListView listView, int firstVisibleItem, int lastVisibleItem) { if (pos < firstVisibleItem || pos > lastVisibleItem) { // The next line is the only downside of this solution I have // found so far. If the convertView of the getView(int // position, View convertView, ViewGroup parent) method is null // the holder pattern I applied in my adapter becomes useless. // In my case the recreation of the CheckedTextViews is fast // enough though. return listView.getAdapter().getView(pos, null, listView); } else { return listView.getChildAt(pos - firstVisibleItem); } }
Okay, I found a good solution: the OnScrollListener provides all I need, while the OnGlobalLayoutListener is not needed here.
public class ArrayListAdapter extends ArrayAdapter<String> implements AbsListView.OnScrollListener ... @Override public void onScrollStateChanged(AbsListView view, int scrollState) {} @Override public synchronized void onScroll(final AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { List<Integer>yList = new ArrayList<>(); int checkedPosition = listView.getCheckedItemPosition(); double yChecked = 0; for (int pos = 0; pos < totalItemCount; pos++) { CheckedTextView tv = (CheckedTextView) this .getViewByPosition(pos, listView, firstVisibleItem, firstVisibleItem + visibleItemCount - 1); if (pos == checkedPosition) { yChecked = tv.getY(); } yList.add(pos, tv.getY()); } // Here I pass the fresh y-values to the fragment holding the // two ListViews. After some further calculations the fragment // passes the data to the TextView where it is stored and // this.invalidate is called to eventually trigger the onDraw method. originalFragment.setScrollData(yList, yChecked); } private View getViewByPosition(int pos, AbsListView listView, int firstVisibleItem, int lastVisibleItem) { if (pos < firstVisibleItem || pos > lastVisibleItem) { // The next line is the only downside of this solution I have // found so far. If the convertView of the getView(int // position, View convertView, ViewGroup parent) method is null // the holder pattern I applied in my adapter becomes useless. // In my case the recreation of the CheckedTextViews is fast // enough though. return listView.getAdapter().getView(pos, null, listView); } else { return listView.getChildAt(pos - firstVisibleItem); } }
相关问答
更多-
foreach (ListViewItem item in myListView.Items) { Rectangle result = item.Bounds; if(result.IntersectsWith(myListView.ClientRectangle)) { //there you go } } 有关Bounds更多信息,请点击此处 ...
-
删除ListView中的项目(Removing items in ListView)[2022-11-11]
删除for loop项目时, 向后循环: for (int i = listView1.Items.Count - 1; i >= 0; --i) if (listView1.Items[i].SubItems[2].Text == "") listView1.Items[i].Remove(); 或者将for循环修改成 for (int i = 0; i < listView1.Items.Count; ) // no ++i here if (listView1.Items[i].S ... -
ListView移动项目(ListView moving items)[2023-05-22]
尝试这个: ////// Move the given item to the given index in the given group /// ///The item and group must belong to the same ListView public void MoveToGroup(ListViewItem lvi, ListViewGroup group, int indexInGroup) { ... -
使用可变大小的项目获取ListView总高度[重复](Getting ListView total Height with Variable size items [duplicate])[2023-12-23]
对于在滚动视图中使用ListView,您需要获取列表视图的高度,然后添加到滚动视图。 以下链接将帮助您完美解决您的问题。 Hiren Dedaniya的回答 For Use Listview inside scroll view you need to get height of of the listview and then add to the scrollview. this below link will help and perfect solution of your problem. Ans ... -
正如King King所说,在控件上启用双缓冲修复了问题: typeof(Control).GetProperty("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(yourListView, true, null); As stated by King King, enabling double buffering on the control fixed the problem: typeof(C ...
-
ListView项目没有出现(ListView Items are not appearing)[2022-04-27]
只有替换下面的ViewModel代码才能保留其余部分 private async void GetAllUsersFromServer() { ListtmpRegisteredUsers = new List (); var registeredPeople =await UserService.Instance.GetAllUsers(); foreach (var names in registeredPeople ... -
做这样的事情, ArrayList
checkedPositions = new ArrayList (); myListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView> arg0, View view, int positio ... -
好的,我找到了一个很好的解决方案:OnScrollListener提供了我所需要的一切,而这里不需要OnGlobalLayoutListener。 public class ArrayListAdapter extends ArrayAdapter
implements AbsListView.OnScrollListener ... @Override public void onScrollStateChanged(AbsListView view, int scrollSt ... -
我通过在更改列表内容时和显示ListView之前动态计算ListView高度来解决我的问题。 从此链接复制代码。 public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return ...
-
您应该在适配器类中执行此操作,模型项需要具有后台资源属性。 只需转换适配器,获取上一个或下一个项目,设置新背景并通知listView public void OnItemClick(AdapterView> parent, View, view, int position, long id){ YourAdapterClass adapter = (YourAdapterClass) parent.getAdapter(); // TODO check if is a valid p ...