android可扩展列表视图

时间:2011-06-01 08:00:41

标签: android position expandablelistview click

我正在使用可扩展列表,但我想知道用户点击了哪个项目的位置 我使用过onitemclick但它没有告诉我msg ..
我在做什么错?

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());
    }

1 个答案:

答案 0 :(得分:1)

尝试使用此功能来处理点击孩子的时间:

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

    }
};