Consolidate a large number of open Source library projects (vi) ListView animation, Activity "abstraction", incidentally, "abstract class" and "interface"

Source: Internet
Author: User

Reprint please indicate the source: Wang 亟亟 's way of Daniel

Yesterday sent a self-written simple such as edittext a custom control, but seemingly not very good response, here to push a push, I hope you give comments and support: http://blog.csdn.net/ddwhan0123/article/details/50235151

OK, back to the last time, added a "Personal development: interface, I hope to put some of their own writing after the inside, as a" large lib "use, so simply the content and interface set a bit, but also roughly distinguish the next column, this display or to the ListView is good, up and down.

It's just a little bit of it, slowly loading the effect.

Say, add the benefits of this effect:

1. In the process of loading can do some asynchronous things, reduce the load of the system

2. Make the entire page appear softer

Realize:

<ListView     android:id="@+id/codeListView"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:choiceMode="singleChoice"     android:layoutAnimation="@anim/code_item_anim" />

Only need to add android:layoutAnimation="@anim/code_item_anim" in the ListView
Point to a animation, and of course you can add it in Java code.

One is implemented as an animation, and a seat is loaded every time with a delay.

Here is the material used to paste the file:

Code_item_anim

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"    android:animation="@anim/list_anim"    android:animationOrder="normal"    android:delay="0.1" />

List_anim.xml

<?xml version= "1.0" encoding= "Utf-8"?><set xmlns:android="Http://schemas.android.com/apk/res/android" >    <translate android:fromxdelta=" -100%"android:fromydelta="0" Android:toxdelta= "0"android:toydelta= "0"android:duration=" 2550 "android:interpolator=" @android: Anim/anticipate_overshoot_interpolator " />                                         </Set>

Activity and adapter code in the source to find, the article will be posted at the end.

Besides, the abstraction of the activity.

Usually, what do we do with some common methods?
1. Write the tool class, call (this I feel is the most).

2. Write a public parent class, and then use the protected method of the parent class (dialog and the like are used more).

3. Other.

Well, then I'll stick to the so-called "abstraction."

 Public Abstract  class Son extends Activity{    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (GetLayout ());        Bindid ();        Init ();        Setonclick ();    Logic (); } Public Abstract int GetLayout(); Public Abstract void Bindid(); Public Abstract void Init(); Public Abstract void Setonclick(); Public Abstract  void Logic();}

There is a class called son inherited from the activity, there are a series of abstract methods (of course, these abstract methods are not abstract do not matter, but must be abstract class)

Then there's another class that inherits son.

//像这样只是继承了publicclass CodeActivity extends Son 

So, to integrate an abstract class, it is necessary to implement his abstract method, like this

  @Override     Public int GetLayout() {LOGUTILS.D ("--->codeactivity getlayout");returnR.layout.activity_code; }@Override     Public void Init() {    }@Override     Public void Bindid() {    }@Override     Public void Setonclick() {    }@Override     Public void Logic() {LOGUTILS.D ("--->codeactivity logic"); }

That's the code, and that's why we're doing it.

The oncreate approach to our complex activity is actually where we want to code the most, from Findviewbyid to Setonclicklistener, and then possibly some other business logic operation.

But I am such an abstraction, indirectly the OnCreate method is layered, each method is very clear to tell others (read your code of people), you this is about what, make the code more readable, logic clearer.

Of course, there are a lot of small partners in the activity inside wrote a such as private void init(); and then in the OnCreate method Init (), in fact, it is OK, but it is possible that every activity you have to do, but now, we only need to extends Son can do these things, why not?

Here is just an example, you can also declare interface to do, but also the same effect.

Like this: http://blog.csdn.net/a_running_wolf/article/details/49359923

Let's take a look at the basics:

Abstract class

Abstract classes are used to capture the generic properties of subclasses. It cannot be instantiated and can only be used as a superclass of subclasses. Abstract classes are templates that are used to create inheritance-level lining classes

Base class

publicabstractclass GenericServlet implements Servlet, ServletConfig, Serializable {    // abstract method    abstractvoid service(ServletRequest req, ServletResponse res);    void init() {        // Its implementation    }    // other method related to Servlet}

Realize

public   Class  httpservlet  extends  genericservlet  { void  Service (ServletRequest req, Servletresponse res) {//implementation } prote CTED  void  doget  (httpservletrequest req, HttpServletResponse resp) {//implementation }  protected  void  dopost  ( HttpServletRequest req, HttpServletResponse resp) {//implementation }  //some other methods related to HttpServlet }  

Interface

An interface is a collection of abstract methods. If a class implements an interface, it inherits the abstract method of the interface. This is like a contract pattern, and if you implement this interface, you must ensure that you use these methods. An interface is just a form, and the interface itself cannot do anything.

Interface:

publicinterface Externalizable extends Serializable {    voidthrows IOException;    voidthrows IOException, ClassNotFoundException;}

Realize:

 Public  class Employee implements externalizable {    intEmployeeId; String EmployeeName;@Override     Public void readexternal(ObjectInput in)throwsIOException, classnotfoundexception {employeeId = In.readint ();    EmployeeName = (String) in.readobject (); }@Override     Public void writeexternal(ObjectOutput out)throwsIOException {out.writeint (employeeId);    Out.writeobject (EmployeeName); }}

Source Address: Https://github.com/ddwhan0123/SoyiGit/tree/master/Soyi

Remember to order a praise Oh, thank you for your support!

Consolidate a large number of open Source library projects (vi) ListView animation, Activity "abstraction", incidentally, "abstract class" and "interface"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.