为什么我的 activity 没有显示?
Why isn't my activity showing?
我正在尝试显示 Spinner 和 TextView,该应用程序运行但屏幕空白。
这是我的 Java 代码
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import java.util.ArrayList;
/**
* Created by ????? on 4/11/2015.
*/
public class CarSelectionActivity extends FragmentActivity {
public void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.new_car_screen);
Spinner _make_spinner = (Spinner) findViewById(R.id.make_spinner);
String[] spinnerArray= getResources().getStringArray(R.array.make_array);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_spinner_item, spinnerArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_make_spinner.setAdapter(adapter);
}
}
这是我的XML布局代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spinner Dropdown"
android:layout_margin="5dp"
android:padding="10dp"
android:textSize="20dp"
android:background="#ff5500"
android:textColor="#fff"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:popupBackground="#FFFF99"
android:id="@+id/make_spinner"
/>
</RelativeLayout>
这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.omnination.ossusum.gallonator" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".CarSelectionActivity"
android:label="Gallonator" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的清单有我的地图片段的代码,但我还没有测试它。
你在这行有问题;-
android:方向="vertical"
Relativelayout--> 你不能给它添加 orientation 属性。删除此行
我正在尝试显示 Spinner 和 TextView,该应用程序运行但屏幕空白。 这是我的 Java 代码
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import java.util.ArrayList;
/**
* Created by ????? on 4/11/2015.
*/
public class CarSelectionActivity extends FragmentActivity {
public void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.new_car_screen);
Spinner _make_spinner = (Spinner) findViewById(R.id.make_spinner);
String[] spinnerArray= getResources().getStringArray(R.array.make_array);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_spinner_item, spinnerArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_make_spinner.setAdapter(adapter);
}
}
这是我的XML布局代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spinner Dropdown"
android:layout_margin="5dp"
android:padding="10dp"
android:textSize="20dp"
android:background="#ff5500"
android:textColor="#fff"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:popupBackground="#FFFF99"
android:id="@+id/make_spinner"
/>
</RelativeLayout>
这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.omnination.ossusum.gallonator" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".CarSelectionActivity"
android:label="Gallonator" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的清单有我的地图片段的代码,但我还没有测试它。
你在这行有问题;-
android:方向="vertical"
Relativelayout--> 你不能给它添加 orientation 属性。删除此行