如何在java中使用空格或空间替代物?
xml
<ListView
android:id="@+id/bus schedules"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>给我错误的代码
findViewById(R.id.bus schedules)
编辑
我在吸毒。
int panelId = getResources().getIdentifier(Selection.toLowerCase(),
"id,drawable", getActivity().getPackageName());因此,我的Selection必须与@+/id相同,否则它将return 0作为无效语句,而my Selection是字符串(string-数组)的显示。
Edit2
我在使用TextView
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.menufragment, container, false);
int i = getArguments().getInt(SELECTION_NUMBER);
String Selection = getResources().getStringArray(R.array.Selection_array)[i];
int panelId = getResources().getIdentifier(Selection.toLowerCase(),
"id", getActivity().getPackageName());
rootView.findViewById(panelId);
getActivity().setTitle(drawerSelection);
return rootView;
}SELECTION_NUMBER来自selectItem(int position),所以它返回上面的位置号shit,取这个数字并在array中找到字符串,并尝试将其与R.java中的某些内容相匹配。
如何去工作
发布于 2013-06-13 02:04:53
命名ID时不能有空间。
此处应用的规则与变量命名或文件命名规则相同。您可以使用_(下面的naming )来命名ID。
您的ID必须以字母表开头,并可以后面跟着数字。
例如有效ID
android:id="@+id/bus_schedules"例如无效ID
android:id="@+id/bus schedules"但是,当您希望在bus schedules中具有可读性时,还有一种方法。你可以用下面这样的句子,
android:id="@+id/BusSchedules"发布于 2013-06-13 03:05:55
android命名规则不允许在定义id的同时允许空间。我建议你使用underscore(_).
android:id="@+id/bus schedules" 至
android:id="@+id/bus_schedules"https://stackoverflow.com/questions/17078102
复制相似问题