看了视频和百度的资料,自己摸索了下。

第一种:系统默认布局

public class MainActivity extends ListActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        String[] names = {"name1","name2","name3"};        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,names);        setListAdapter(adapter);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);        return true;    }    @Override    public boolean onOptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {            return true;        }        return super.onOptionsItemSelected(item);    }}

第二种:使用自定义布局

public class MainActivity extends ListActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);                //与上一个演示唯一的区别在这里,你可以设置自己想要的布局        setContentView(R.layout.activity_main);                String[] names = {"name1","name2","name3"};        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,names);        setListAdapter(adapter);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);        return true;    }    @Override    public boolean onOptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {            return true;        }        return super.onOptionsItemSelected(item);    }}
      

自己演示了看看吧

更多相关文章

  1. Android(安卓)Message和obtainMessage的区别
  2. Android(安卓)fill_parent和wrap_content分析
  3. Android(安卓)代码中动态为RadioGroup添加RadioButton
  4. android之LinearLayout
  5. Android设置布局背景为白色的三种方法
  6. android 可自定义大小和位置的Dialog
  7. Java乔晓松-android使用ImageSwitcher布局的电子相册&服务器获取
  8. android浏览器研究-APP层UI布局
  9. Android(安卓)学习记录-布局预览错误

随机推荐

  1. MySQL慢查日志的开启方式与存储格式详析
  2. MySQL 使用DQL命令查询数据的实现方法
  3. MySQL5.6解压版服务无法启动之系统错误10
  4. MySQL InnoDB MRR优化指南
  5. MySQL索引不会被用到的情况汇总
  6. MySQL性能优化神器Explain的基本使用分析
  7. CentOS 安装redis和MySQL
  8. 简单谈谈MySQL数据透视表
  9. MySQL中USING 和 HAVING 用法实例简析
  10. MYSQL数据库表结构优化方法详解