启动列表的activity

每学一个知识点就要重新创建一个项目,感觉那样太繁琐了,特别是android studio开发,没创建一个项目都会重新打开一个窗口

所以我就在那想,何不有一个功能列表,点击每一个列表项的时候就跳转到那个功能界面里

android里有一个launcherActivity,只需要我们的app 启动activity继承此activity就可以了

 1 /**
 2  * 展示功能列表的activity
 3  */
 4 public class FuncListActivity extends LauncherActivity{
 5 
 6     private List<LauncherListItemDesc> itemList;
 7     private MyAdapter adapter;
 8 
 9     @Override
10     protected void onCreate(Bundle savedInstanceState) {
11         super.onCreate(savedInstanceState);
12 
13         //初始化功能列表数据
14         initItemList();
15 
16         adapter = new MyAdapter();
17         setListAdapter(adapter);
18     }
19 
20     /**
21      * 点击某一个列表项时返回一个意图
22      * @param position
23      * @return
24      */
25     @Override
26     protected Intent intentForPosition(int position) {
27         return itemList.get(position).getIntent();
28     }
29 
30     private class MyAdapter extends BaseAdapter{
31 
32         @Override
33         public int getCount() {
34             return itemList.size();
35         }
36 
37         @Override
38         public View getView(int position, View convertView, ViewGroup parent) {
39             TextView view;
40             if (convertView != null) {
41                 view = (TextView) convertView;
42             }else {
43                 view = (TextView) View.inflate(getApplicationContext(), android.R.layout.simple_list_item_1, null);
44             }
45             view.setText(itemList.get(position).getDesc());
46             view.setTextColor(Color.BLACK);
47 
48             return view;
49         }
50 
51         @Override
52         public Object getItem(int position) {
53             return null;
54         }
55 
56         @Override
57         public long getItemId(int position) {
58             return 0;
59         }
60 
61 
62     }
63 
64     /**
65      * 每添加一个功能就在此添加数据
66      */
67     private void initItemList() {
68         itemList = new ArrayList<>();
69 
70         //动画activity
71         itemList.add(new LauncherListItemDesc("nineold anim", new Intent(FuncListActivity.this, AnimActivity.class)));
72     }
73 
74 }
原文地址:https://www.cnblogs.com/zhengqun/p/4599260.html