Items in ListView not reacting

Im programming an app and I created a slide-in-menu containing a ListView.

But the items aren't clickable. After clicking one of the items the slide-in-menu closes and nothing happens, although it should toast something.

Here is my Code:

    statsdrawerLayout = (DrawerLayout)findViewById(R.id.statsdrawerlayout);
    statslist = (ListView)findViewById(R.id.statslist);

    statslist.setOnItemClickListener(this);

    ArrayList<String> graphArray = new ArrayList<String>();

    graphArray.add("Feuchtigkeit");
    graphArray.add("Sonneneinstrahlung");
    graphArray.add("Windeschwindigkeit");
    graphArray.add("Außen-Temperatur");
    graphArray.add("Alle Graphen zurücksetzen");

    statslist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, graphArray);
    statslist.setAdapter(adapter);

    statslist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    statslist.setFocusable(false);
    statslist.setFocusableInTouchMode(false);

    statsdrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

    actionBarDrawerToggle = new ActionBarDrawerToggle(this,statsdrawerLayout, R.string.openstats,R.string.closestats);
    statsdrawerLayout.addDrawerListener(actionBarDrawerToggle);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

Below my onCreate I placed my onItemClick:

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    switch(position){
        case 0:

            Toast.makeText(StatistikAllGraphs.this, "Clicked", Toast.LENGTH_SHORT).show();
        break;

    }
}

There are 4 other cases but it's way too much code to place it in here.

Here's the important part out of my layout file:

?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/statsdrawerlayout">


    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fragmentholder">
    </FrameLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/statslist"
        android:layout_gravity="start"
        android:clickable="true"
        android:background="@color/Orange">
    </ListView>
</android.support.v4.widget.DrawerLayout>

Thanks in advance.

Xaver Seiringer

Answers


have you set the listview.onitemclicklistener(this) in your oncreate and have you implemented the listview.onitemclicklistener? and try putting break; inside the case block after the toast.


Need Your Help

Auto click button and web scraping

javascript php jquery wordpress html5

i try to get some data from a webpage and to put it in an array (php or javascript) or a database.

Auto detect internal/external development environment

php development-environment production-environment autodiscovery

We use the following function to auto detect if we are on a machine internally or on a live server and then choose the appropriate configs for various components: