我设置了一个简单的列表视图,但它只显示一个白色的屏幕。在onOptionsItemSelected的主要活动中,我有以下代码。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Fintons cafe</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link rel="apple-touch-icon" href="apple-touch-icon.png">-->
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700' rel='stylesheet' type='text/css'>
<!--if your on a subpage-->
<link rel="stylesheet" href="../lib/css/bootstrap.min.css">
<link rel="icon" href="../lib/img/favicon.jpg" type="image/x-icon">
<link rel="stylesheet" href="../lib/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="../lib/css/main.css">
<link rel="stylesheet" type="text/css" href="../lib/css/tabs.css">
<script src="../lib/js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
<script src="../lib/js/main.js"></script>
<script src="../lib/js/vendor/jquery-1.11.2.min.js"></script>
</head>
<body>
<header class="site-header">
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<img src="../lib/img/logo1.png" class="hidden-xs visible-sm visible-md visible-lg visible-xl" />
<img src="../lib/img/logo1.png" class="visible-xs hidden-sm" style="width:200px;" />
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a class="nav-link" href="/">Home</a></li> <!--ensures 'Home' is first in list-->
<!--site.pages is selected by MD root elements-->
<!--site.pages is selected by MD root elements-->
<!--ensures that only pages are selected (by checking the title validity), otherwise all root elements are selected-->
<!--hack for making Home go to the left-->
<li><a class="nav-link" href="/about/">About Us</a></li>
<!--site.pages is selected by MD root elements-->
<!--ensures that only pages are selected (by checking the title validity), otherwise all root elements are selected-->
<!--hack for making Home go to the left-->
<li><a class="nav-link" href="/contact/">Contact</a></li>
<!--site.pages is selected by MD root elements-->
<!--site.pages is selected by MD root elements-->
<!--ensures that only pages are selected (by checking the title validity), otherwise all root elements are selected-->
<!--site.pages is selected by MD root elements-->
<!--site.pages is selected by MD root elements-->
<!--site.pages is selected by MD root elements-->
<!--site.pages is selected by MD root elements-->
<!--site.pages is selected by MD root elements-->
<!--ensures that only pages are selected (by checking the title validity), otherwise all root elements are selected-->
<!--hack for making Home go to the left-->
<!--if this is the current page-->
<li><a class="nav-link selected" href="#">Menu</a></li>
</ul>
</div>
</nav>
</header>
<div class="page-content">
<div class="wrapper">
<article class="post">
<header class="post-header">
<h1 class="post-title">Menu</h1>
</header>
<div class="post-content">
</div>
</article>
</div>
</div>
<br />
<footer class="site-footer">
<div class="wrapper">
<center>Copyright © 2016 | Designed by <a href="mailto:rhys.oconnor@outlook.com?Subject=Fintons%20Website">Rhys O'Connor</a></center>
</div>
</footer>
</html>
</body>
</html>
问题是什么?
Intent l = new Intent(getApplicationContext(),AboutTest.class);
startActivity(l);
活性
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView">
</ListView>
</RelativeLayout>
答案 0 :(得分:2)
您正在覆盖onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
,但只有在API级别21或更高版本中将persistableMode设置为true的活动才会调用该方法。
相反,您应该覆盖不同的onCreate(),如下所示:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_test);
ListView myList = (ListView)findViewById(R.id.listView);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, list);
myList.setAdapter(adapter);
}