1

I followed this link and the answer with most results gives me that the method, setOnGroupExpandListener cannot be resolved. I'm new to android and currently doing stuff basically by checking out how others have done it and try to learn from them.

ExpendableListAdapter listAdapter;
ExpandableListView expListView;
private int lastExpandedPosition = -1;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;

expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

    @Override
    public void onGroupExpand(int groupPosition) {
        if (lastExpandedPosition != -1
                && groupPosition != lastExpandedPosition) {
            expListView.collapseGroup(lastExpandedPosition);
        }
        lastExpandedPosition = groupPosition;
    }
});

This is in my MainActivity.java, setOnGroupExpandListener is underlined and "not resolved".

These are the imported classes:

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ExpandableListView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

This is the content of my build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.kevin.ha1kattai"
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

This is my project file

Community
  • 1
  • 1
Banana
  • 604
  • 7
  • 22

1 Answers1

2

Android ExpandableListView Support Min SDK:10. Please change YourminSdkVersion .

android:minSdkVersion An integer designating the minimum API Level required for the application to run.

Please set minSdkVersion as 13 or 17 for better approach

Edited

 defaultConfig {
    applicationId "com.example.kevin.ha1kattai"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
IntelliJ Amiya
  • 70,230
  • 14
  • 154
  • 181