简体   繁体   中英

android expandable list view

i am using expandable list but i want know position of which item is clicked by user
i have used onitemclick but it doesn't show me msg..
what wrong i am doing?

public void funName(){
    File ringtones_directory = new File(DIRECTORY);
    if (!ringtones_directory.exists()) {
        AlertDialog.Builder ad = new AlertDialog.Builder(
                FindFilesByType.this);
        ad.setTitle("Directory Not Found");
        ad.setMessage("Sorry! The ringtones directory doesn't exist.");
        ad.setPositiveButton("OK", null);
        ad.show();

        hasErrors = true;
    }

    if (!ringtones_directory.canRead()) {
        AlertDialog.Builder ad = new AlertDialog.Builder(
                FindFilesByType.this);
        ad.setTitle("Permissions");
        ad
                .setMessage("Sorry! You don't have permission to list the files in that folder");
        ad.setPositiveButton("OK", null);
        ad.show();
        hasErrors = true;
    } else {
        Ringtones = FindFiles(false);

        if (Ringtones.size() < 1) {
            AlertDialog.Builder ad = new AlertDialog.Builder(
                    FindFilesByType.this);
            ad.setTitle("Permissions");
            ad.setMessage("Sorry! No ringtones exists in " + DIRECTORY
                    + ".");
            ad.setPositiveButton("OK", null);
            ad.show();
            Log.e(LOG_TAG, "No ringtones were found.");
            hasErrors = true;
        }

    }

    try {

        if (!hasErrors) {
            // refreshList();
            // this.lv1.setAdapter(new ArrayAdapter<String>(
            // FindFilesByType.this, android.R.layout.test_list_item,
            // Ringtones));
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                    FindFilesByType.this, android.R.layout.test_list_item,
                    Ringtones);
            ArrayList<String> GrouppList = new ArrayList<String>();
            GrouppList.addAll(Ringtones);
            ArrayList<ArrayList<Color>> colors = new ArrayList<ArrayList<Color>>();
            for(int i=0;i<=Ringtones.size();i++){
            ArrayList<Color> color = new ArrayList<Color>();

            color = new ArrayList<Color>();

            color.add(new Color(" ", "", true));

            colors.add(color);}
            expListAdapter = new ColorAdapter(this, GrouppList, colors);
        //  setListAdapter(expListAdapter);
            exlv1=(ExpandableListView) findViewById(R.id.expandableListView1);
            this.exlv1.setAdapter(expListAdapter);
            //exlv1.setAdapter(expListAdapter);
            this.exlv1.setOnItemClickListener(new OnItemClickListener() {
//THIS METHOD NOT WORKING FOR ME
                @Override
                public void onItemClick(AdapterView<?> aview, View v,
                        int position, long id) {
                    Toast.makeText(FindFilesByType.this, "position "+position, Toast.LENGTH_LONG).show();//THIS DOESNOT WORKING
                    // TODO Auto-generated method stub

                }
            });


        }

    } catch (Exception e) {
        Toast.makeText(this, "Error " + e.toString(), Toast.LENGTH_LONG)
                .show();
        Log.i(LOG_TAG, e.toString());
    }

Try this to handle when a child is clicked:

exlv1.setOnChildClickListener(new OnChildClickListener() {
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
            int childPosition, long id) {

    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM