Custom Controls-android list grouping and letter navigation

Source: Internet
Author: User

Custom Controls-android list grouping and letter navigation

With the refactoring of the above two articles, it is very easy to refactor the ListView group list to a custom control. You only need to put the initialization operation in the constructor of the custom control. The restructured custom control is based on the annotation refactoring in the previous article.

Basic Structure

First, paste the code structure of the activity after reconstruction in the previous article. The implementation of relevant methods have been posted in the previous two articles.


Paste the structure of the restructured View. It can be seen that both structures are similar. The difference is that there is an abstract method getDataList () in the above activity, but not below, but there is an ILoadRulerData ILoadData interface. Load data.


In the custom View, the initdata () method in the activity is changed to loaddata () for the data to be loaded after the active call. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PC9wPgo8cD7W2Lm5uvO7 + bG + expires + ytfPyMrHyv2 + 3bzT1Ni907/ao7o8L3A + expires = "brush: java;"> public interface ILoadRulerData {Public List GetDataList ();}

Then the basic code of the custom view is as follows:

/*** @ Description: You need to call setiLoadData first, set the interface for obtaining data, and then call the loadData Method */public class RulerView
 
  
Extends LinearLayout {private View baseView; private TextView noDataView; private TextView RulerTag; private ProgressBarWithText progress; private ListView listView; private RulerWidget r.pdf; private ILoadRulerData
  
   
ILoadData; private List
   
    
OriginalList; public List
    
     
> DealedList; private HashMap
     
      
TagLocation = new HashMap
      
        (); Private RulerAdapter
       
         RulerAdapter; public RulerView (Context context) {super (context); init (context);} public RulerView (Context context, AttributeSet attrs) {super (context, attrs ); init (context);} public RulerView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs); init (context);}/*** @ Description: set the data loading interface * @ param * @ return void */public void setiLoadData (ILoadRulerData
        
          ILoadData) {this. iLoadData = iLoadData;} private void init (Context context) {baseView = LayoutInflater. from (context ). inflate (R. layout. g_rw, null); noDataView = (TextView) baseView. findViewById (R. id. g_base_list_nodata); RulerTag = (TextView) baseView. findViewById (R. id. g_ruler_tag); progress = (ProgressBarWithText) baseView. findViewById (R. id. g_base_progressbar_withtext); listView = (ListView) ba SeView. findViewById (R. id. g_base_list); rbytes = (RulerWidget) baseView. findViewById (R. id. g_rss); progress. setVisibility (View. VISIBLE); RulerTag. setVisibility (View. GONE); noDataView. setVisibility (View. GONE); listView. setVisibility (View. GONE); rloud. setVisibility (View. GONE); addView (baseView, LayoutParams. MATCH_PARENT, LayoutParams. WRAP_CONTENT);} public void loadData () {new getdataasytask(cmd.exe cu Te ();}..... }
        
       
      
     
    
   
  
 

Test layout
 
        
     <******.ruler.view.RulerView       android:id="@+id/test_ruler_view_id"       android:layout_width="match_parent"       android:layout_height="wrap_content"       />
 

Activity
public class TestViewActivity extends Activity{           private RulerView
 
   rulerView;     @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.test_ruler_view);        rulerView = (RulerView
  
   ) findViewById(R.id.test_ruler_view_id);        rulerView.setiLoadData(new ILoadRulerData
   
    () {                     @Override           public List
    
      getDataList() {                           return new TestAnnnoDao().getBoList();           }       });        rulerView.loadData();          }}
    
   
  
 

This series is complete.

Related Article

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.