Preparation, analysis:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/121U0IG-0.jpg "title =" homepage .jpg "alt =" 145125710.jpg"/>
After analyzing this interface, we mainly use several tabbars to manage different interfaces. First, we will think of TabActivity. This is our previous practice. Android is getting better and better, and its functions are getting better and better, we also need to update our technology at any time, or we will be eliminated. TabActivity has been eliminated by google. Now most of the practices have been replaced by TabHost and Fragment. This article uses the FragmentTabHost class.
See http://developer.android.com/reference/android/support/v13/app/FragmentTabHost.html for details
Http://blog.csdn.net/yangyu20121224/article/details/9016223
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/121U01426-1.jpg "title =" qq 31021155235.jpg "alt =" 155313334.jpg"/>
FragmentTabhost is actually an encapsulation of TabHost, so that we can develop it more quickly.
The specific usage of FragmentTabhost is similar to that of TabHost, except that the Activity is replaced with Fragment. Fragment brings great convenience to our development, however, every time the annoying things occur, the onCreateView () will stop countless developers. I am also learning how to improve it. Currently, I have only used fragment to write two projects, in general, I still like this stuff. The switching effect is much better than the Activity!
The following describes the problems encountered and the problems that need attention:
-
Resolution Adaptation: resolution adaptation)
-
In the running android program, press the home Key to return to the desktop, click the program image again, and restart the program. Solution: remove the Startup Mode set for the first entry of the program Activity. android: launchMode = "singleTask" need to understand the knowledge of the android Startup Mode http://www.cnblogs.com/fanchangfa/archive/2012/08/25/2657012.html online have organized a lot, I am not very good, do not explain more
-
Log tool: You can copy the Logger class from the util package in the project.
-
All images used in this application are from the Sina Weibo client (if there is any infringement, please tell me)
Start, build
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/121U01352-2.jpg "title =" qq 31021223312.jpg "alt =" 223411515.jpg"/>
This is a common subcontracting method, which is mainly divided by component type:
-
Build configuration class, base class, application class)
-
Build a tool class (in fact, it refers to the summary tool class CV)
-
The connection part adopts a common framework: android-async-http
-
Image loading is also very important in android: Android-Universal-Image-Loader
-
Pull up and pull Refresh: Android-PullToRefresh
When you see this, there will certainly be a lot of people who will think: Using others' security is not good, easy to use is not good (if you have good, you can share it)-I have also written it myself, some operations of http are not as good as those encapsulated by others. Since it is not as good as that of open source, it can be applied directly. If it is not suitable, it can be modified by itself. Why not? There are also many open-source class libraries bound to click events on the ui, which are not found in this application...
// ========== All activities inherit the class, used to implement some basic operations
/*** Application base class ** @ author Johnny **/public class BaseActivity extends FragmentActivity {public MyHandler myHandler; protected ProgressDialog progressDialog; @ Override protected void onCreate (Bundle arg0) {// TODO Auto-generated method stub super. onCreate (arg0); init ();} private void init () {myHandler = new MyHandler (this); progressDialog = new ProgressDialog (this); progressDialog. setProgressStyle (ProgressDialog. STYLE_SPINNER); progressDialog. setCancelable (true); progressDialog. setMessage ("loading"); progressDialog. setCanceledOnTouchOutside (false);} public static class MyHandler extends Handler {WeakReference <BaseActivity> baseActivitys; MyHandler (BaseActivity baseActivity) {baseActivitys = new WeakReference <BaseActivity> (baseActivity );} @ Override public void handleMessage (Message msg ){/ /Define a Handler for processing the communication between the download thread and the UI if (! Thread. currentThread (). isInterrupted () {final BaseActivity baseActivity = baseActivitys. get (); switch (msg. what) {case AppConfig. SHWO_PROGRESS: baseActivity. progressDialog. show (); // display the progress dialog box break; case AppConfig. HIDE_PROGRESS: baseActivity. progressDialog. hide (); // hide the progress dialog box. dismiss () and cancel () are not allowed. Otherwise, when show () is called again, the small circle of the displayed dialog box does not change. (WebView) break; case AppConfig. DISS_PROGRESS: baseActivity. progressDialog. dismiss (); // close the progress dialog box case AppConfig. NET_ERR_SHOW: baseActivity. toastShow (AppConfig. NET_ERR); // network exception break; case AppConfig. DATA_ERR_SHOW: baseActivity. toastShow (AppConfig. DATA_ERR); // Data Exception break; default: baseActivity. getMessage (msg); break;} super. handleMessage (msg) ;}}; public void showProgress () {myHandler. sendEmptyMessage (AppConfig. SHWO_PROGRESS);} public void hideProgress () {myHandler. sendEmptyMessage (AppConfig. HIDE_PROGRESS);} public void dissProgress () {myHandler. sendEmptyMessage (AppConfig. DISS_PROGRESS);} public void netErrShow () {myHandler. sendEmptyMessage (AppConfig. NET_ERR_SHOW);} public void dataErrShow () {myHandler. sendEmptyMessage (AppConfig. DATA_ERR_SHOW);} public void sendMessage (int what) {myHandler. sendEmptyMessage (what);} public void sendMessage (Message msg) {myHandler. sendMessage (msg);} public void sendMessage (Message msg, long delayMillis) {myHandler. sendMessageDelayed (msg, delayMillis);} public void ToastShow (String content) {ToastUtils. show (BaseActivity. this. getApplicationContext (), content);}/*** receiver Message implementation class override this method to receive messages * @ param msg */protected void getMessage (Message msg ){}}
// ===================== Main Interface
/*** Main interface ** @ author Johnny **/public class ksinaactivity extends BaseActivity {private FragmentTabHost mFth; private writable list <Class <?> Classes; private LayoutInflater layoutInflater; // layout loading manager private int mImageView [] = {R. drawable. tab_home, R. drawable. tab_message, R. drawable. tab_profile, R. drawable. tab_discover, R. drawable. tab_more}; // Tab icon private String mTextview [] = {"Homepage", "message", "me", "square", "more "}; // Tab title @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. a Ctivity_kksina); initData (); initView ();} private void initData () {// TODO Auto-generated method stub classes = new category list <Class <?> (); Classes. add (HomeFragment. class); classes. add (MessageFragment. class); classes. add (ProfileFragment. class); classes. add (DiscoverFragment. class); classes. add (MoreFragment. class);} private void initView () {// TODO Auto-generated method stub layoutInflater = LayoutInflater. from (this); // instantiate the TabHost object and get TabHost mFth = (FragmentTabHost) findViewById (android. r. id. tabhost); mFth. setup (this, getSupportFra GmentManager (), R. id. realtabcontent); addTab (classes);} private void addTab (final complete list <Class <?> Classes) {int size = classes. size (); for (int I = 0; I <size; I ++) {// set the icon, text, and content TabSpec tabSpec = mFth for each Tab button. newTabSpec (mTextview [I]). setIndicator (getTabItemView (I); // Add the Tab button to the mFth Tab. addTab (tabSpec, classes. get (I), null); mFth. getTabWidget (). getChildAt (I ). setBackgroundResource (R. drawable. tabbar_bg) ;}}/*** set the icon and title for the Tab button */private View getTabItemView (int index) {View view = layoutInflater. inflate (R. layout. tab_item_view, null); ImageView imageView = (ImageView) view. findViewById (R. id. iv_tabbar); imageView. setImageResource (mImageView [index]); TextView textView = (TextView) view. findViewById (R. id. TV _tabbar); textView. setText (mTextview [index]); return view ;}}
// ========================= AdapterBase
/*** Basic Adapter ** @ author Johnny ** @ param <T> */public abstract class AdapterBase <T> extends BaseAdapter {protected List <T> mList = new external List <T> (); public List <T> getList () {return mList;} public void appendToList (List <T> list) {if (list = null) {return;} mList. addAll (list); notifyDataSetChanged ();} public void appendToTopList (List <T> list) {if (list = null) {return;} mList. addAll (0, list); notifyDataSetChanged ();} public void setList (List <T> list) {if (list = null) {return;} mList = list; notifyDataSetChanged ();} public void clear () {mList. clear (); policydatasetchanged () ;}@ Override public int getCount () {// TODO Auto-generated method stub return mList. size () ;}@ Override public T getItem (int position) {// TODO Auto-generated method stub if (position> mList. size ()-1) {return null;} return mList. get (position) ;}@ Override public long getItemId (int position) {// TODO Auto-generated method stub return position ;}@ Override public View getView (int position, View convertView, viewGroup parent) {// TODO Auto-generated method stub if (position = getCount ()-1) {onReachBottom () ;}return getExView (position, convertView, parent );} protected abstract View getExView (int position, View convertView, ViewGroup parent); protected abstract void onReachBottom ();}
End, share
KKsina
This article is from the "KK technology" blog, please be sure to keep this source http://wangyubin.blog.51cto.com/6807757/1312881