-1

I am using DrawerLayout which has Listview

When I click on the Listview item , it does not responds to the click ( not launching another activity )

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);

    final ActionBar actionBar=getActionBar();
    actionBar.setIcon(null);
    actionBar.setTitle("");

    setContentView(R.layout.main_activity);

    // Custom ActionBar initializations.
    getActionBar().setCustomView(R.layout.action_bar_custom);
    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_HOME_AS_UP);
    getActionBar().setDisplayUseLogoEnabled(true);
    getActionBar().setDisplayShowHomeEnabled(true);
    getActionBar().setDisplayShowCustomEnabled(true);
    //getActionBar().setIcon(R.drawable.ic_drawer);




    // Remember me.
    sharedPref=getSharedPreferences("myPref", MODE_PRIVATE);
    editor=sharedPref.edit();


    //Listview
    mDrwawerList=(ListView)findViewById(R.id.list_slidermenu);
    listDataHeader = new ArrayList<HashMap<String,String>>();
    listDataHeader_temp = new ArrayList<String>();
    navigational_adapter=new NavigationListAdapter(MainActivity.this, new ArrayList<HashMap<String,String>>());

    mDrawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout);

    mDrawerToggle=new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.nav_btn,0, 0){
        public void onDrawerClosed(View drawerView){
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu();
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    mDrwawerList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub


            TextView txtCategoryName=(TextView)view.findViewById(R.id.txt_category);
            String category_name=txtCategoryName.getText().toString();

            Log.e("category_name", "karjeevcategory_name "+category_name);

            if (category_name.equals("Home")) {

            }
            else if (category_name.equals("Diamond of the Week")) {

                            }
            else if (category_name.equals("About Us")) {

            }
            else if (category_name.equals("FAQ")) {

                Intent intent=new Intent(MainActivity.this,FAQActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);

            }
            else if (category_name.equals("Press & Download")) {

            }
            else if (category_name.equals("Contact Us")) {

            }


        }
    });    


    new PerformGetCategory().execute();

}
ivan.sim
  • 8,972
  • 8
  • 47
  • 63
karthik kolanji
  • 2,044
  • 5
  • 20
  • 56
  • Are you getting the log which you have declared inside listview item click listner – Pankaj Apr 16 '15 at 09:52
  • no I am not getting it ...... – karthik kolanji Apr 16 '15 at 09:52
  • after your elseif ladder try to add else –  Apr 16 '15 at 09:54
  • NavigationListAdapter which u r initializing, in that you are passing empty arraylist of hashmap. can you pl share the code of NavigationListAdapter. Also navigational_adapter instance of NavigationListAdapter is not set as adapter to your drawerlist. Are you able to see the drawerlist items? – Rajen Raiyarela Apr 16 '15 at 09:58
  • @ Rajen Raiyarela ---- yes ... able to see it – karthik kolanji Apr 16 '15 at 10:04
  • the log `Log.e("category_name", "karjeevcategory_name "+category_name)` prints or not? – Weiyi Apr 16 '15 at 10:14
  • @ li2 ------no ... nothing prints when I click Listview – karthik kolanji Apr 16 '15 at 10:25
  • change the code in lsitview item click listner. Move the log printing line to first before TextView declaration and then see if log is printing or not. – Pankaj Apr 16 '15 at 11:33
  • can u add main_activity.xml n adapter code – Harsha Vardhan Apr 16 '15 at 12:05
  • what the function `invalidateOptionsMenu();` did? why both `onDrawerClosed()` and `onDrawerOpened()` called the same function? – Weiyi Apr 17 '15 at 03:16
  • Does your listview item contain focusable view? To avoid the child focusable view capturing the click event, you should set the child view `android:focusable="false"`, or set listview item `android:descendantFocusability="blocksDescendants"`. Refer to this answer [OnItemCLickListener not working in listview ANDROID](http://stackoverflow.com/a/14372750/2722270) – Weiyi Apr 17 '15 at 04:06
  • Fix code indentation to improve readability. – ivan.sim Apr 17 '15 at 22:11

2 Answers2

0

Replace your existing code with this,and create a Intent inside particular position case of listview, if FAQ item is at 5th position, create Intent inside case 4:

mDrawerList.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                displayView(position);
            }
        });

And inside displayView(int position) keep this:

private void displayView(int position) {
        switch (position) {
            case 0:
                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                 Intent intent=new Intent(MainActivity.this,FAQActivity.class);
                 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                 startActivity(intent);
                 break;
            case 5:
                break;
            case 6:
                break;
            default:
                break;
        }
                }

Hope this solves your problem.

Harsh Dattani
  • 2,109
  • 1
  • 17
  • 27
0

I solved my problem from my end ...

There was layout issues , due to which the listview was not able to handle the click ..

I pasted my litsview code to bottom of the other layout code which was inside DrawerLayout

karthik kolanji
  • 2,044
  • 5
  • 20
  • 56