listView根本没有出现。安卓

胸怀万里世界, 放眼无限未来。这篇文章主要讲述listView根本没有出现。安卓相关的知识,希望能为你提供帮助。
【listView根本没有出现。安卓】listView根本没有出现(活动是白色的,我添加的东西很少(按钮)),我不知道它是否重要,但这不是我的主要活动。
编辑:我为主要活动和项目添加了xml

public class CarsMenu extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cars_menu); runListView(); clickFun(); } private void clickFun() { ListView list = (ListView) findViewById(R.id.MlistView); list.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Override public void onItemClick(AdapterView< ?> parent, View viewClicked, int position, long id) { TextView textView = (TextView) viewClicked; Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_SHORT).show(); } }); } private void runListView(){ String[] getCars = {"blue", "green", "purple", "red"}; ArrayAdapter< String> adapter = new ArrayAdapter< String> (this, R.layout.items,getCars); ListView list = (ListView) findViewById(R.id.MlistView); list.setAdapter(adapter); } }

活动xml
activity xml < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${packageName}.${activityClass}" > < Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:onClick="btnCarClick" android:text="Refresh" /> < ListView android:id="@+id/MlistView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/button1" android:layout_centerHorizontal="true" > < /ListView> < /RelativeLayout>

的;
< ?xml version="1.0" encoding="utf-8"?> < TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > < /TextView>

android清单
< ?xml version="1.0" encoding="utf-8"?> < manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.http" android:versionCode="1" android:versionName="1.0" > < uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> < application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > < activity android:name="com.example.http.MainActivity" android:label="@string/app_name" > < intent-filter> < action android:name="android.intent.action.MAIN" /> < category android:name="android.intent.category.LAUNCHER" /> < /intent-filter> < /activity> < activity android:name="com.example.http.Exception_Error" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/title_activity_exception__error" android:theme="@style/FullscreenTheme" > < /activity> < activity android:name="com.example.http.Menu_Activity" android:label="@string/title_activity_menu_" > < /activity> < activity android:name="com.example.http.Dev" android:label="@string/title_activity_dev" > < /activity> < activity android:name="com.example.http.AllCars" android:label="@string/title_activity_all_cars" > < /activity> < activity android:name="com.example.http.Cars" android:label="@string/title_activity_cars" > < /activity> < activity android:name="com.example.http.CarsMenu" android:label="@string/title_activity_cars_menu" > < /activity> < /application> < uses-permission android:name="android.permission.INTERNET" > < /uses-permission> < /manifest>

答案您的“items.xml”对象的高度等于父级 - 因此列表视图中只能显示一个项目。将其更改为:
< ?xml version="1.0" encoding="utf-8"?> < TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > < /TextView>


    推荐阅读