0

listView doesn't appear at all (the activity is white with few things I added (buttons)) and I don't know if its important but this is not my main activity.

edit: I added xml for main activity and items

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);

    }
}

activity 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>

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="match_parent" >


</TextView>

android manifest

<?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>
8
  • show your activity_cars_menu.xml file
    – Nabin
    Aug 10, 2014 at 9:26
  • where is your activity_cars_menu.xml file?
    – Nabin
    Aug 10, 2014 at 9:36
  • post your acitivity_cars_menu.xml file
    – Nabin
    Aug 10, 2014 at 9:42
  • @Nabin I can't understand how can the manifest be useful here!
    – frogatto
    Aug 10, 2014 at 9:45
  • @Nabin items.xml is having simple textview without any id. By using android default simple_list_item this problem is getting solved. I tested this on my PC
    – Paritosh
    Aug 10, 2014 at 9:47

1 Answer 1

0

Your "items.xml" object has it's height equal to the parent - so only one item will be visible in your listview. Change it to:

<?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>
2
  • wait the function runListView is not setting text for the items in listView? because even after i changed the xml i still get blank list. so how can i add the colors (getCar String Array) to the list? Aug 10, 2014 at 10:32
  • You are setting the data correctly. I use all custom adapters, so it looked wrong. I edited my post. I think you have a different issue now. Try setting text in the item TextView to see if you have a resource/build problem.
    – Jim
    Aug 10, 2014 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.