<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
Category Archives: Android
Can the Android Layout folder contain subfolders?
The answer is no.
I would like to draw your attention towards this book Pro Android 2 that states:
It is also worth noting a few constraints regarding resources. First, Android supports only a linear list of files within the predefined folders under res. For example, it does not support nested folders under the layout folder (or the other folders under res).
Second, there are some similarities between the assets folder and the raw folder under res. Both folders can contain raw files, but the files within raw are considered resources and the files within assets are not.
Note that because the contents of the assets folder are not considered resources, you can put an arbitrary hierarchy of folders and files within it.
Using lists in Android (ListView) – Tutorial
Lars Vogel
Version 4.6
Copyright © 2010, 2011, 2012, 2013, 2014 vogella GmbH
20.11.2014
Using Android ListView, ListActivity and ListFragment
This tutorial describes how to use the ListView view together with Activities and Fragments in Android. The tutorial is based on Eclipse 4.4, Java 1.7 and Android 5.0.
1. Android and Lists
The display of elements in a list is a very common pattern in mobile applications. The user sees a list of items and can scroll through them. Such an activity is depicted in the following picture.

Typically the user interacts with the list via the action bar, for example, via a refresh button. Individual list items can be selected. This selection can update the action bar or can trigger a detailed screen for the selection. The following graphic sketches that. On the selection of a list item another activity is started.

Android provides the ListView and the ExpandableListView classes which is capable of displaying a scrollable list of items.
The ExpandableListView class supports a grouping of items.
The input to the list (items in the list) can be arbitrary Java objects. The adapter extracts the correct data from the data object and assigns this data to the views in the row of the ListView.
These items are typically called the data model of the list. An adapter can receive data as input.
An adapter manages the data model and adapts it to the individual entries in the widget. An adapter extends the BaseAdapter class.
Every line in the widget displaying the data consists of a layout which can be as complex as you want. A typical line in a list has an image on the left side and two text lines in the middle as depicted in the following graphic.

A layout file for a such a line might look like the following.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="6dip" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentBottom="true" android:layout_alignParentTop="true" android:layout_marginRight="6dip" android:contentDescription="TODO" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/secondLine" android:layout_width="fill_parent" android:layout_height="26dip" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_toRightOf="@id/icon" android:ellipsize="marquee" android:singleLine="true" android:text="Description" android:textSize="12sp" /> <TextView android:id="@+id/firstLine" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@id/secondLine" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_alignWithParentIfMissing="true" android:layout_toRightOf="@id/icon" android:gravity="center_vertical" android:text="Example application" android:textSize="16sp" /> </RelativeLayout>
The adapter would inflate the layout for each row in its getView() method and assign the data to the individual views in the row.
The adapter is assigned to the ListView via the setAdapter method on the ListView object.
Tip
Adapters are not only used by ListView, but also by other views which extend AdapterView as, for example, Spinner, GridView, Gallery and StackView.
Filtering and sorting of the data is handled by the adapter. You need to implement the logic in your custom adapter implementation.
The notifyDataSetChanged() method on the adapter is called if the data has changed or if new data is available.
The notifyDataSetInvalidated() method is called if the data is not available anymore.
To react to selections in the list, set an OnItemClickListener to your ListView.
listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), "Click ListItem Number " + position, Toast.LENGTH_LONG) .show(); } });
Android provides default adapter implementations; the most important are ArrayAdapter and CursorAdapter.
ArrayAdapter can handle data based on Arrays or java.util.List.
SimpleCursorAdapter can handle database related data.
The ArrayAdapter class can handle a list or array of Java objects as input. Every Java object is mapped to one row. By default, it maps the toString() method of the object to a view in the row layout.
You can define the ID of the view in the constructor of the ArrayAdapter otherwise the android.R.id.text1 ID is used as default.
The ArrayAdapter class allows to remove all elements in its underlying data structure with the clear() method call. You can then add new elements via the add() method or a Collection via the addAll() method.
You can also directly modify the underlying data structure and call the notifyDataSetChanged() method on the adapter to notify it about the changes in data.
Warning
If you want to change the data in your adapter, the underlying data structure must support this operation. This is, for example, the case for the ArrayList class, but not for arrays.
The following listing shows a layout file called activity_listviewexampleactivity.xml which includes a ListView.
<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview" android:layout_width="wrap_content" android:layout_height="wrap_content" />
The following example shows the usage of the ListView view in an activity. It uses a default layout from the Android platform for the row layout. It also demonstrates the removal of list items and uses animations for the removal.
package com.vogella.android.listview.withanimation; public class ListViewExampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_listviewexampleactivity); final ListView listview = (ListView) findViewById(R.id.listview); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2", "Android", "iPhone", "WindowsMobile" }; final ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < values.length; ++i) { list.add(values[i]); } final StableArrayAdapter adapter = new StableArrayAdapter(this, android.R.layout.simple_list_item_1, list); listview.setAdapter(adapter); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { final String item = (String) parent.getItemAtPosition(position); view.animate().setDuration(2000).alpha(0) .withEndAction(new Runnable() { @Override public void run() { list.remove(item); adapter.notifyDataSetChanged(); view.setAlpha(1); } }); } }); } private class StableArrayAdapter extends ArrayAdapter<String> { HashMap<String, Integer> mIdMap = new HashMap<String, Integer>(); public StableArrayAdapter(Context context, int textViewResourceId, List<String> objects) { super(context, textViewResourceId, objects); for (int i = 0; i < objects.size(); ++i) { mIdMap.put(objects.get(i), i); } } @Override public long getItemId(int position) { String item = getItem(position); return mIdMap.get(item); } @Override public boolean hasStableIds() { return true; } } }
The ArrayAdapter is limited as it supports only the mapping of toString() to one view in the row layout. To control the data assignment and to support several views, you have to create your custom adapter implementation.
For this you would extend an existing adapter implementation or subclass the BaseAdapter class directly.
Tip
Frequently you extend ArrayAdapter to write a custom adapter, as this is simpler than extending BaseAdapter directly.
The adapter needs to create a layout for each row of the list. The ListView instance calls the getView() method on the adapter for each data element. In this method the adapter creates the row layout and maps the data to the views in the layout.
This root of the layout is typically a ViewGroup (layout manager) and contains several other views , e.g., an ImageView and a TextView. The following graphic shows a list with different layouts for odd and even rows.

Within the getView() method you would inflate an XML based layout and then set the content of the individual views based on the Java object for this row. To inflate the XML layout file, you can use the LayoutInflator system service.
Note
This layout inflator service can get accessed via the getLayoutInflator() method of the activity or via the context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) method call.
After the adapter inflated the layout, it searches for the relevant views in the layout and fills them with the data. The individual elements in the layout can be found via the findViewById() method call on the top level view.
The following code shows an implementation of a custom adapter. This adapter assumes that you have two png files (no.png and yes.png) in one of your res/drawable folders. The coding inflates an XML layout file, finds the relevant views in the layout and sets their content based on the input data.
package de.vogella.android.listactivity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; public class MySimpleArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public MySimpleArrayAdapter(Context context, String[] values) { super(context, R.layout.rowlayout, values); this.context = context; this.values = values; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.rowlayout, parent, false); TextView textView = (TextView) rowView.findViewById(R.id.label); ImageView imageView = (ImageView) rowView.findViewById(R.id.icon); textView.setText(values[position]); // change the icon for Windows and iPhone String s = values[position]; if (s.startsWith("iPhone")) { imageView.setImageResource(R.drawable.no); } else { imageView.setImageResource(R.drawable.ok); } return rowView; } }
Android provides specialized fragment and activity classes to simplify list handling.
The classes are the ListActivity class if you want to use lists in activities and the the ListFragment class if you want to use lists in fragments.
You do not have to assign a layout to these elements. If you do not define a layout, the activity or fragment contains a single ListView by default. ListActivity and ListFragment also allow you to override a onListItemClick() method for handling selection of list items.
Both classes allow you to set the adapter to the default ListView via the setListAdapter() method.
The following example code shows a simple ListFragment implementation.
package de.vogella.android.fragments; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.app.ListFragment; public class MyListFragment extends ListFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, values); setListAdapter(adapter); } @Override public void onListItemClick(ListView l, View v, int position, long id) { // do something with the data } }
The next example code demonstrates the usage of a ListActivity.
package de.vogella.android.listactivity; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class MyListActivity extends ListActivity { public void onCreate(Bundle icicle) { super.onCreate(icicle); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values); setListAdapter(adapter); } }
You can use a custom layout with ListActivity or ListFragment. In this case the fragment or activity searches in the provided layout for a ListView with the pre-defined android:id attribute set to @android:id/list. This usage is demonstrated by the following code snippet.
<ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView>
Warning
If you do not use this ID or do not include a ListView into your layout, the application crashes once you try to display the activity or the fragment.
The following exercise demonstrates how to use a ListView in an ListActivity. You use the predefined ArrayAdapter class and an existing Android layout for the rows.
Create a new Android project called de.vogella.android.listactivity with the activity called MyListActivity.
Change MyListActivity class based on the the following code example. Note that the setContentView() method is not used.
package de.vogella.android.listactivity; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class MyListActivity extends ListActivity { public void onCreate(Bundle icicle) { super.onCreate(icicle); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values); setListAdapter(adapter); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { String item = (String) getListAdapter().getItem(position); Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show(); } }

In our example your will define your layout for the rows and use it in your adapter.
Create the rowlayout.xml layout file in the res/layout folder of the de.vogella.android.listactivity project.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:id="@+id/icon" android:layout_width="22px" android:layout_height="22px" android:layout_marginLeft="4px" android:layout_marginRight="10px" android:layout_marginTop="4px" android:src="@drawable/ic_launcher" > </ImageView> <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@+id/label" android:textSize="20px" > </TextView> </LinearLayout>
Change your activity so that is using the new layout.
package de.vogella.android.listactivity; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class MyListActivity extends ListActivity { public void onCreate(Bundle icicle) { super.onCreate(icicle); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; // use your custom layout ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.rowlayout, R.id.label, values); setListAdapter(adapter); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { String item = (String) getListAdapter().getItem(position); Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show(); } }

The following uses two images “no.png” and “ok.png”. I placed it in the “res/drawable-mdpi” folder. You must create your own icons. In case you do not find any icons just copy “icon.png” and use a drawing program to change it a little bit.
Create the class MySimpleArrayAdapter which will serve as our adapter.
package de.vogella.android.listactivity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; public class MySimpleArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public MySimpleArrayAdapter(Context context, String[] values) { super(context, R.layout.rowlayout, values); this.context = context; this.values = values; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.rowlayout, parent, false); TextView textView = (TextView) rowView.findViewById(R.id.label); ImageView imageView = (ImageView) rowView.findViewById(R.id.icon); textView.setText(values[position]); // Change the icon for Windows and iPhone String s = values[position]; if (s.startsWith("Windows7") || s.startsWith("iPhone") || s.startsWith("Solaris")) { imageView.setImageResource(R.drawable.no); } else { imageView.setImageResource(R.drawable.ok); } return rowView; } }
To use this adapter, change the activity to the following.
package de.vogella.android.listactivity; import android.app.ListActivity; import android.os.Bundle; public class MyListActivity extends ListActivity { public void onCreate(Bundle icicle) { super.onCreate(icicle); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(this, values); setListAdapter(adapter); } }
If you run this example you should get a list with different icons for the certain elements.

Android studio 快捷键
Alt+回车 导入包,自动修正
Ctrl+N 查找类
Ctrl+Shift+N 查找文件
Ctrl+Alt+L 格式化代码
Ctrl+Alt+O 优化导入的类和包
Alt+Insert 生成代码(如get,set方法,构造函数等)
Ctrl+E或者Alt+Shift+C 最近更改的代码
Ctrl+R 替换文本
Ctrl+F 查找文本
Ctrl+Shift+Space 自动补全代码
Ctrl+空格 代码提示
Ctrl+Alt+Space 类名或接口名提示
Ctrl+P 方法参数提示
Ctrl+Shift+Alt+N 查找类中的方法或变量
Alt+Shift+C 对比最近修改的代码
Shift+F6 重构-重命名
Ctrl+Shift+先上键
Ctrl+X 删除行
Ctrl+D 复制行
Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者 )
Ctrl+J 自动代码
Ctrl+E 最近打开的文件
Ctrl+H 显示类结构图
Ctrl+Q 显示注释文档
Alt+F1 查找代码所在位置
Alt+1 快速打开或隐藏工程面板
Ctrl+Alt+ left/right 返回至上次浏览的位置
Alt+ left/right 切换代码视图
Alt+ Up/Down 在方法间快速移动定位
Ctrl+Shift+Up/Down 代码向上/下移动。
F2 或Shift+F2 高亮错误或警告快速定位
代码标签输入完成后,按Tab,生成代码。
选中文本,按Ctrl+Shift+F7 ,高亮显示所有该文本,按Esc高亮消失。
Ctrl+W 选中代码,连续按会有其他效果
选中文本,按Alt+F3 ,逐个往下查找相同文本,并高亮显示。
Ctrl+Up/Down 光标跳转到第一行或最后一行下
Ctrl+B 快速打开光标处的类或方法
最常用快捷键
1.Ctrl+E,可以显示最近编辑的文件列表
2.Shift+Click可以关闭文件
3.Ctrl+[或]可以跳到大括号的开头结尾
4.Ctrl+Shift+Backspace可以跳转到上次编辑的地方
5.Ctrl+F12,可以显示当前文件的结构
6.Ctrl+F7可以查询当前元素在当前文件中的引用,然后按F3可以选择
7.Ctrl+N,可以快速打开类
8.Ctrl+Shift+N,可以快速打开文件
9.Alt+Q可以看到当前方法的声明
10.Ctrl+W可以选择单词继而语句继而行继而函数
11.Alt+F1可以将正在编辑的元素在各个面板中定位
12.Ctrl+P,可以显示参数信息
13.Ctrl+Shift+Insert可以选择剪贴板内容并插入
14.Alt+Insert可以生成构造器/Getter/Setter等
15.Ctrl+Alt+V 可以引入变量。例如把括号内的SQL赋成一个变量
16.Ctrl+Alt+T可以把代码包在一块内,例如try/catch
17.Alt+Up and Alt+Down可在方法间快速移动
下面的不是很有用
18.在一些地方按Alt+Enter可以得到一些Intention Action,例如将”==”改为”equals()”
19.Ctrl+Shift+Alt+N可以快速打开符号
20.Ctrl+Shift+Space在很多时候都能够给出Smart提示
21.Alt+F3可以快速寻找
22.Ctrl+/和Ctrl+Shift+/可以注释代码
23.Ctrl+Alt+B可以跳转到抽象方法的实现
24.Ctrl+O可以选择父类的方法进行重写
25.Ctrl+Q可以看JavaDoc
26.Ctrl+Alt+Space是类名自动完成
27.快速打开类/文件/符号时,可以使用通配符,也可以使用缩写
28.Live Templates! Ctrl+J
29.Ctrl+Shift+F7可以高亮当前元素在当前文件中的使用
30.Ctrl+Alt+Up /Ctrl+Alt+Down可以快速跳转搜索结果
31.Ctrl+Shift+J可以整合两行
32.Alt+F8是计算变量值
IntelliJ IDEA使用技巧一览表
在使用 InelliJ IDEA 的过程中,通过查找资料以及一些自己的摸索,发现这个众多 Java 程序员喜欢的 IDE 里有许多值得一提的小窍门,如果能熟练的将它们应用于实际开发过程中,相信它会大大节省你的开发时间,而且随之而来的还会有那么一点点成就感:) Try it !
1 、写代码时用 Alt-Insert ( Code|Generate… )可以创建类里面任何字段的 getter 与 setter 方法。
2 、右键点击断点标记(在文本的左边栏里)激活速查菜单,你可以快速设置 enable/disable 断点或者条件它的属性。
3 、 CodeCompletion (代码完成)属性里的一个特殊的变量是,激活 Ctrl-Alt-Space 可以完成在或不在当前文件里的类名。如果类没有引入则 import 标志会自动创建。
4 、使用 Ctrl-Shift-V 快捷键可以将最近使用的剪贴板内容选择插入到文本。使用时系统会弹出一个含有剪贴内容的对话框,从中你可以选择你要粘贴的部分。
5 、利用 CodeCompletion (代码完成)属性可以快速地在代码中完成各种不同地语句,方法是先键入一个类名地前几个字母然后再用 Ctrl-Space 完成全称。如果有多个选项,它们会列在速查列表里。
6 、用 Ctrl-/ 与 Ctrl-Shift-/ 来注释 / 反注释代码行与代码块。
-/ 用单行注释标记(“ //… ”)来注释 / 反注释当前行或者选择地代码块。而 Ctrl-Shift-/ 则可以用块注释标记(“ ”)把所选块包围起来。要反注释一个代码块就在块中任何一个地方按 Ctrl-Shift-/ 即可。
7 、按 Alt-Q ( View|Context Info )可以不需要移动代码就能查看当前方法地声明。连续按两次会显示当前所编辑的类名。
8 、使用 Refactor|Copy Class… 可以创建一个所选择的类的“副本”。这一点很有用,比如,在你想要创建一个大部分内容都和已存在类相同的类时。
9 、在编辑器里 Ctrl-D 可以复制选择的块或者没有所选块是的当前行。
10 、 Ctrl-W (选择字)在编辑器里的功能是先选择脱字符处的单词,然后选择源代码的扩展区域。举例来说,先选择一个方法名,然后是调用这个方法的表达式,然后是整个语句,然后包容块,等等。
11 、如果你不想让指示事件细节的“亮球”图标在编辑器上显示,通过按 Alt-Enter 组合键打开所有事件列表然后用鼠标点击它就可以把这个事件文本附件的亮球置成非活动状态。
这样以后就不会有指示特殊事件的亮球出现了,但是你仍然可以用 Alt-Enter 快捷键使用它。
12 、在使用 CodeCompletion 时,可以用逗点( . )字符,逗号(,)分号(;),空格和其它字符输入弹出列表里的当前高亮部分。选择的名字会随着输入的字符自动输入到编辑器里。
13 、在任何工具窗口里使用 Escape 键都可以把焦点移到编辑器上。
Shift-Escape 不仅可以把焦点移到编辑器上而且还可以隐藏当前(或最后活动的)工具窗口。
F12 键把焦点从编辑器移到最近使用的工具窗口。
14 、在调试程序时查看任何表达式值的一个容易的方法就是在编辑器中选择文本(可以按几次 Ctrl-W 组合键更有效地执行这个操作)然后按 Alt-F8 。
15 、要打开编辑器脱字符处使用的类或者方法 Java 文档的浏览器,就按 Shift-F1 (右键菜单的 External JavaDoc )。
要使用这个功能须要把加入浏览器的路径,在“ General ”选项中设置( Options | IDE Settings ),另外还要把创建的 Java 文档加入到工程中( File | Project Properties )。
16 、用 Ctrl-F12 ( View | File Structure Popup )键你可以在当前编辑的文件中快速导航。
这时它会显示当前类的成员列表。选中一个要导航的元素然后按 Enter 键或 F4 键。要轻松地定位到列表中的一个条目,只需键入它的名字即可。
17 、在代码中把光标置于标记符或者它的检查点上再按 Alt-F7 (右键菜单中的 Find Usages… )会很快地查找到在整个工程中使用地某一个类、方法或者变量的位置。
18 、按 Ctrl-N ( Go to | Class… )再键入类的名字可以快速地在编辑器里打开任何一个类。从显示出来的下拉列表里选择类。
同样的方法你可以通过使用 Ctrl-Shift-N ( Go to | File… )打开工程中的非 Java 文件。
19 、要导航代码中一些地方使用到的类、方法或者变量的声明,把光标放在查看项上再按 Ctrl-B 即可。也可以通过按 Ctrl 键的同时在查看点上单击鼠标键调转到声明处。
20 、把光标放到查看点上再按 Ctrl-Alt-B 可以导航到一个抽象方法的实现代码。
21 、要看一个所选择的类的继承层次,按 Ctrl-H ( Browse Type Hierarchy )即可。也可以激活编辑器中的继承关系视图查看当前编辑类的继承关系。22 、使用 Ctrl-Shift-F7 ( Search | Highlight Usages in File )可以快速高亮显示当前文件中某一变量的使用地方。按 Escape 清除高亮显示。
23 、用 Alt-F3 ( Search | Incremental Search )在编辑器中实现快速查查找功能。
在“ Search for: ”提示工具里输入字符,使用箭头键朝前和朝后搜索。按 Escape 退出。
24 、按 Ctrl-J 组合键来执行一些你记不起来的 Live Template 缩写。比如,键“ it ”然后按 Ctrl-J 看看有什么发生。
25 、 Introduce Variable 整合帮助你简化代码中复杂的声明。举个例子,在下面的代码片断里,在代码中选择一个表达式:然后按 Ctrl-Alt-V 。
26 、 Ctrl-Shift-J 快捷键把两行合成一行并把不必要的空格去掉以匹配你的代码格式。
27 、 Ctrl-Shift-Backspace ( Go to | Last Edit Location )让你调转到代码中所做改变的最后一个地方。
多按几次 Ctrl-Shift-Backspace 查看更深的修改历史。
28 、用 Tools | Reformat Code… 根据你的代码样式参考(查看 Options | IDE Setting | Code Style )格式化代码。
使用 Tools | Optimize Imports… 可以根据设置(查看 Options | IDE Setting | Code Style | Imports )自动“优化” imports (清除无用的 imports 等)。
29 、使用 IDEA 的 Live Templates | Live Templates 让你在眨眼间创建许多典型代码。比如,在一个方法里键入
再按 Tab 键看有什么事情发生了。
用 Tab 键在不同的模板域内移动。查看 Options | Live Templates 获取更多的细节。
30 、要查看一个文件中修改的本地历史,激活右键菜单里的 Local VCS | Show History… 。也许你可以导航不同的文件版本,看看它们的不同之处再回滚到以前的任何一个版本吧。
使用同样的右键菜单条目还可以看到一个目录里修改的历史。有了这个特性你就不会丢失任何代码了。
31 、如果要了解主菜单里每一个条目的用途,把鼠标指针移到菜单条目上再应用程序框架的底部的状态栏里就会显示它们的一些简短描述,也许会对你有帮助。
32 、要在编辑器里显示方法间的分隔线,打开 Options | IDE Settings | Editor ,选中“ Show method separators ”检查盒( checkbox )。
33 、用 Alt-Up 和 Alt-Down 键可以在编辑器里不同的方法之间快速移动。
34 、用 F2/Shift-F2 键在高亮显示的语法错误间跳转。
用 Ctrl-Alt-Down/Ctrl-Alt-Up 快捷键则可以在编译器错误信息或者查找操作结果间跳转。
35 、通过按 Ctrl-O ( Code | Override Methods… )可以很容易地重载基本类地方法。
要完成当前类 implements 的(或者抽象基本类的)接口的方法,就使用 Ctrl-I ( Code | Implement Methods… )。
36 、如果光标置于一个方法调用的括号间,按 Ctrl-P 会显示一个可用参数的列表。
37 、要快速查看编辑器脱字符处使用的类或方法的 Java 文档,按 Ctrl-Q (在弹出菜单的 Show Quick JavaDoc 里)即可。
38 、像 Ctrl-Q ( Show Quick JavaDoc 显示简洁 Java 文档), Ctrl-P ( Show Parameter Info 显示参数信息), Ctrl-B ( Go to Declaration 跳转到声明), Shift-F1 ( External JavaDoc 外部 Java 文档)以及其它一些快捷键不仅可以在编辑器里使用,也可以应用在代码完成右键列表里。
39 、 Ctrl-E ( View | Recent Files )弹出最近访问的文件右键列表。选中文件按 Enter 键打开。
40 、在 IDEA 中可以很容易地对你的类,方法以及变量进行重命名并在所有使用到它们的地方自动更正。
试一下,把编辑器脱字符置于任何一个变量名字上然后按 Shift-F6 ( Refactor | Rename… )。在对话框里键入要显示地新名字再按 Enter 。你会浏览到使用这个变量地所有地方然后按“ Do Refactor ”按钮结束重命名操作。
41 、要在任何视图( Project View 工程视图, Structure View 结构视图或者其它视图)里快速
选择当前编辑地部分(类,文件,方法或者字段),按 Alt-F1 ( View | Select in… )。
42 、在“ new ”字符后实例化一个已知类型对象时也许你会用到 SmartType 代码完成这个特性。比如,键入
再按 Ctrl-Shift-Space :
43 、通过使用 SmartType 代码完成,在 IDEA 中创建接口的整个匿名 implementation 也是非常容易的,比如,对于一些 listener (监听器),可以键入
Component component;
component.addMouseListener(
new
);
然后再按 Ctrl-Shift-Space 看看有什么发生了。
44 、在你需要设置一个已知类型的表达式的值时用 SmartType 代码完成也很有帮助。比如,键入
String s = (
再按 Ctrl-Shift-Space 看看会有什么出现。
45 、在所有视图里都提供了速查功能:在树里只需键入字符就可以快速定位到一个条目。
46 、当你想用代码片断捕捉异常时,在编辑器里选中这个片断,按 Ctrl-Alt-T ( Code | Surround with… )然后选择“ try/catch ”。它会自动产生代码片断中抛出的所有异常的捕捉块。在 Options | File Templates | Code tab 中你还可以自己定制产生捕捉块的模板。
用列表中的其它项可以包围别的一些结构。
47 、在使用代码完成时,用 Tab 键可以输入弹出列表里的高亮显示部分。
不像用 Enter 键接受输入,这个选中的名字会覆盖掉脱字符右边名字的其它部分。这一点在用一个方法或者变量名替换另一个时特别有用。
48 、在声明一个变量时代码完成特性会给你显示一个建议名。比如,开始键入“ private FileOutputStream ”然后按 Ctrl-Space
工作笔记 ORDER
概念:
目前来说系统只维系一个在点的单,也就是同一时间给别人点单的这个LIST只有一个。这个单得CHECKOUT了后才能再点另外一个单。然后每个单点了后就立马发给数据库了,要读CURRENT单得话直接从数据库里读CURRENT ORDER。CURRENT ORDER代表的是这个单SOMEHOW没有完结。但过了24小时的单就自动会规划到完结单里面。到HISTORY ORDER里面。如果一个ORDER# 为-1到-100,则被看做当前正在点的单。如果是-100以下或0以上,代表是离线单或者是从SERVER读的单,代表不是正在点的单。
STAFF 点单
UIComponentActivity
里面有一个Order mOrder来TRACK当前ORDER
有一个createNewOrderIfNull(), 此方法检查ORDER是否为空,当前是否有ORDER,如果没有,建立一个新的ORDER,设置ORDER_ID为-1。在ORDER里面建立一个OPLIST,里面包含了这个ORDER里面有哪些PRODUCTS,每个PRODUCT点的数量等。
当点一个菜时,首先判断当前又没ORDER,如果没有,新建一个ORDER, 写入数据库。然后调用ADDITEM把新的PRODUCT加进这个ORDER。如果已有ORDER,CHECK ORDER是否已被支付,或者已被送到厨房,确认是否要更改。
客人点单
MY ORDER上显示当前在点的单,当当前单发,显示历史单。
如何把PRODUCT存入ORDER里
在PRODUCT和ORDER中间有一层ORDER_PRODUCT,因为两个表是MM关系。在PRODUCT里是没有一个ORDERPRODUCTLIST。相反在ORDER里有一个ORDERPRODUCT LIST。用来TRACK一个ORDER里有哪些PRODUCT。把一个PRODUCT放入ORDER的方式是先创建一个Orders_Products,然后放进ORDER的OP表里。
Can’t upload Android app to device (stale dexed jars)
Simple Solution: restart your device!
工作笔记 -表与表的联系
实例表:
P:Product
P_Cat: Product category
包含一个List<P> pList: 每个CATEGORY可以从这个LIST找到他所对应的PRODUCT
P_Opts: Product options
包含一个P_Opts_Descr pod 和 P_Opts_Grp pog
P_Opts_Grp pog 相当于一个连接P_OPTS_GRP的外KEY,所以可以从每个OPTION里找到他所对应的OPTION GROUP
P_Opts_Grp: Product options group
里面有一个public List <P_Opts> poList=new ArrayList<P_Opts>(),记录这个GROUP包含了哪些OPTIONS
关系表:
所有加2的表,比如P2Opts, P2Pog等
ACTIVITY会在一开始就从本地服务器读进所有数据,这样就可以减少IO,加快速度。这时很多数据先会存在关系表里。然后再在COMBINE的方法里面,把这些数据存进实例表CLASS的对应变量里。
工作笔记 tabbar
在PRODUCT DETAIL ACTIVITY来显示点击一件PRODUCT后的页面。这里将会显示三个TAB,每个TAB在SET CONTENT里都用的THIS参数,代表着不使用或调转新的FRAGMENT或ACTIVITY。这只需要原有ACTIVITY实现TABCONTENTFACTORY这个INTERFACE。然后override createTabContent里就好了。
工作笔记 pcLIST(product category list) ,pListTab(products list)
在CUSTOMER MAIN ACTIVITY里,
pListTab记录着单独一个CATEGORY里放的所有PRODUCT,比如BBQ,SALAD,这些都在TOP TAB里可以选
public static List<P> pListTab = new ArrayList<P>();
当TOP BAR里的一个ITEM被选中后,会调用MENUFRAGMENT里的REFRESH PRODUCT方法,该方法会从CUSTOMER ACTIVITY里先获取一个PCLIST(PRODUCT CATEGORY LIST)。这个表是个树状数组,主KEY是PRODUCT CATEGORY,每个PRODUCT CATEGORY对应着一个PRODUCT LIST。所以再获取PCLIST后,先读取你选中的那个PRODUCT CATEGORY的PRODUCT LIST。然后再把CUSTOMER MAIN ACTIVITY里的PLISTTAB换成新选出的这个,最后调用GRID ADAPTER去刷新。
public void refreshProductTab(String tabId) {
this.pListTab = CustomerMainActivity.pcList.get(Integer.parseInt(tabId)).pList;
CustomerMainActivity.pListTab = this.pListTab;
adapter.notifyDataSetChanged();
}
工作笔记 – TAB的切换
POSMIL里的TAB由TABHOST CLASS生成,每个TAB点击对应的CONTENT其实就是这个ACTIVITY本身,没有什么变化。但当TAB切换时,会调用TAB切换LISTERNER,根据对应的TAB ID,FRAGMENT MANAGER会让不同的FRAGMENT去DYNAMIC覆盖这个TAB对应的CONTENT页面而实行调动