LauncherActivity在应用中开发的作用

LauncherActivity在应用中开发的作用

说起LauncherActivity非常简单, LauncherActivity的作用在于形成一个列表,然后没有一个列表点击产生一个intent条状到相关的界面去。

当然作为程序猿的我们完全可以使用ListView + Intent实现其功能,并且能随心所欲。毕竟自己做的自己能Hold住。

但是系统给你这样一个类是有原因的,他们也不是没事找事做。
下面介绍一下LauncherActivity:
LauncherActivity继承了ListView,所以还是一个ListActivity,则需要为它设置Adapter-----可以时非常简单的数组适配器arrayAdapter,可以使用SimpleAdapter,
任性的是还可以自己创建Adapter-->BaseAdapter。特别需要注意 特别注意    注意  的是它没有 setContentView()( 重要的事情说三遍)
要想点击不同的列表项启动对应的Activity,则需要重写intentForPosition(int position)。
贴一段简单的代码:
setListAdapter(adapter)  就相当于 setContentView();
仔细想想 其实在很多地方度可以使用LauncherActivity(游戏的选项里。。。。)
import android.app.Activity;
import android.app.ExpandableListActivity;
import android.app.LauncherActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;


public class MainActivity extends LauncherActivity {
    String[] name = {"设置程序参数","查看星际兵种"};
    Class<?>[] clazzs = {PreferenceActivityTest.class, ExpandableListActivityTest.class};
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,name);
        setListAdapter(adapter);
    }

    @Override
    protected Intent intentForPosition(int position) {
        return new Intent(MainActivity.this, clazzs[position]);
    }
}


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值