启动列表的activity
生活随笔
收集整理的這篇文章主要介紹了
启动列表的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
總結
以上是生活随笔為你收集整理的启动列表的activity的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CUDA编程技术汇总
- 下一篇: cuda编程基础