編輯:關於Android編程
先看效果圖:
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+0qrKtc/W1eK49tCnufujrGFjdGl2aXR5sdjQ68q1z9ZFeHBhbmRhYmxlTGlzdEFjdGl2aXR5PC9wPgo8cD48L3A+CjxwcmUgY2xhc3M9"brush:java;"> @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mContactListView = getExpandableListView();
mContactListView.setBackgroundResource(R.drawable.default_bg);
registerForContextMenu(mContactListView);
mContactDataBase = ((ContactApplication) getApplication())
.getmContactDataBase();
getExpandableListView().setCacheColorHint(0);// 拖動時避免出現黑色
getExpandableListView().setDivider(null);// 去掉每項下面的黑線(分割線)
// 自定義下拉圖標
getExpandableListView().setGroupIndicator(
getResources().getDrawable(R.drawable.expander_ic_folder));
setAdatperForExpandableListView();
}
/**
* 設置ExpandableListView的adapter
*/
private void setAdatperForExpandableListView() {
Cursor groupCursor = mContactDataBase.getAllGroups(); //這個是從數據庫裡查詢出所有的組
Util.d(TAG, "groupCursor=" + groupCursor);
// curosr的生命周期將和activity有關
startManagingCursor(groupCursor);
// set my adapter
ContactTreeAdapter contactTreeAdapter = new ContactTreeAdapter(
groupCursor, this, true, mContactDataBase);
setListAdapter(contactTreeAdapter);
}
主要實現ContactTreeAdapter這個adapter
public class ContactTreeAdapter extends CursorTreeAdapter { /** log tag. */ private static final String TAG = "ContactTreeAdapter"; /** context */ public Context mContext = null; private Cursor mCursor = null; private ContactDataBase mContactDataBase; // contact表字段索引 private static final int INDEX_NAME = 1; private static final int INDEX_PHONENUMBER = 2; // group表字段索引 private static final int INDEX_GROUPNAME = 1; public ContactTreeAdapter(Cursor cursor, Context context, boolean autoRequery, ContactDataBase contactDataBase) { super(cursor, context, autoRequery); mContext = context; this.mContactDataBase = contactDataBase; // TODO Auto-generated constructor stub } @Override protected Cursor getChildrenCursor(Cursor groupCursor) { // TODO Auto-generated method stub String groupName = groupCursor.getString(INDEX_GROUPNAME);// 得到當前的組名 Cursor childCursor = mContactDataBase.getContactsByGroupName(groupName); return childCursor; } @Override protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) { // TODO Auto-generated method stub Util.d(TAG, "newGroupView"); LayoutInflater inflate = LayoutInflater.from(mContext); View view = inflate.inflate(R.layout.grouplayout, null); bindGroupView(view, context, cursor, isExpanded); return view; } @Override protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) { // TODO Auto-generated method stub Util.d(TAG, "bindGroupView"); TextView groupName = (TextView) view.findViewById(R.id.groupName); String group = cursor.getString(INDEX_GROUPNAME); groupName.setText(group); TextView groupCount = (TextView) view.findViewById(R.id.groupCount); int count = mContactDataBase.getCountContactByGroupName(group); Util.d(TAG, "count=" + count + "group=" + group); groupCount.setText("[" + count + "]"); } @Override protected View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) { // TODO Auto-generated method stub Util.d(TAG, "newChildView"); LayoutInflater inflate = LayoutInflater.from(mContext); View view = inflate.inflate(R.layout.childlayout, null); bindChildView(view, context, cursor, isLastChild); return view; } @Override protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) { // TODO Auto-generated method stub Util.d(TAG, "bindChildView cursor.getString(INDEX_PHONENUMBER)=" + cursor.getString(INDEX_PHONENUMBER)); TextView name = (TextView) view.findViewById(R.id.name); name.setText(cursor.getString(INDEX_NAME)); TextView description = (TextView) view.findViewById(R.id.description); description.setTextKeepState(cursor.getString(INDEX_PHONENUMBER)); } }
在Android Studio裡面想設置代碼風格,在這裡我想把代碼風格從Java的行尾式改成C風格的代碼,如下 if(true) { // TODO}if
Android WebView In NestedScrollView 加載騰訊新聞頁面 點擊彈出層 bug 小記。目的是: CoordinatorLayou+AppBa
本Demo中所含功能1:定位,顯示當前位置2:地圖多覆蓋物(地圖描點,彈出該點的詳細信息)3:坐標地址互相換算4:POI興趣點檢索5:線路查詢(步行,駕車,公交)6:繪制
最近看了一大堆的自定義View多數都可以充當耗時操作的交互界面,再接再厲再傳一個SubmitView,一個和可用於模仿提交等待與用戶交互用的一個自定義View