0

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

1 Answers1

0

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.

dione llorera
  • 357
  • 4
  • 14
  • I used AdapterView.OnItemClickListener and forgot setOnItemClickListener. I edited my code but it still doesnt work. – Xaver Seiringer Apr 08 '16 at 23:47
  • try making the listview clickable on the xml file ahaha and your break make the k small – dione llorera Apr 09 '16 at 00:29
  • Didnt work, dont know what to do anymore. i actually answered 3 days ago but it was deleted somehow – Xaver Seiringer Apr 11 '16 at 17:23
  • sorry for the late reply. i suggest you follow the guide on this one http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html proper way of creating drawer and having items clickable inside it. follow it and youll achieve what you want. hehehe – dione llorera Apr 12 '16 at 00:21
  • or the easiest clone what have i done https://github.com/lloreradondi/ShoppingCartMobile.git and just review the code – dione llorera Apr 12 '16 at 00:31