我无法在我的可扩展列表适配器中使用 openFileInput() 方法

I am not able to use openFileInput() method in my Expandable list adapter

我一直在尝试一种方法来读取我的文件 subs.txt。我知道它在那里,因为它在我的另一个 类 中有效,但在这个中无效。在我的缓冲区 reader 上,我得到一个无文件异常,当我使用 openFileinput 时,我得到 "cannot find symbol method openFileInput()".

     public class ExpandableAdapter extends BaseExpandableListAdapter {

    private Activity activity;
    private ArrayList<Object> childtems;
    private LayoutInflater inflater;
    private ArrayList<String> parentItems, child;

    public ExpandableAdapter(ArrayList<String> parents, ArrayList<Object> childern) {
        this.parentItems = parents;
        this.childtems = childern;
    }

    public void setInflater(LayoutInflater inflater, Activity activity) {
        this.inflater = inflater;
        this.activity = activity;
    }




    @Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

        child = (ArrayList<String>) childtems.get(groupPosition);

        TextView textView = null;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.group, null);
        }

        textView = (TextView) convertView.findViewById(R.id.textView1);
        textView.setText(child.get(childPosition));
        //textView.setText(Html.fromHtml("<a href=http://www.whosebug.com> STACK OVERFLOW "));
        // textView.setMovementMethod(LinkMovementMethod.getInstance());
        convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                try {
                    String link="";
                    ArrayList<String>a=child;
                    FileInputStream fin = openFileInput("subs.txt");
                    String test=child.get(childPosition);
                    String objEnc = "";
                    File myFile = new File( "subs.txt");
                    BufferedReader br = new BufferedReader(new FileReader(myFile));

                    StringBuilder sbuilder = new StringBuilder();
                    objEnc = br.readLine();
                    while (objEnc != null) {
                        sbuilder.append(objEnc);
                        objEnc = br.readLine();
                        if (objEnc != null) {

                            // sbuilder.append("\n");

                        }
                    }
                    br.close();
                    objEnc=sbuilder.toString();
                    objEnc=sbuilder.toString();
                    Gson gson = new Gson();
                    ManySubs obj = gson.fromJson(objEnc, ManySubs.class);
                    for(int i=0;i<obj.newPosts.size();i++){
                        for(int j=0;j<obj.newPosts.get(i).list.size();j++){
                            if(obj.newPosts.get(j).list.get(j).equals(test)){
                                link=obj.newPosts.get(j).list.get(j).url;
                            }

                        }
                    }
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
                    activity.startActivity(browserIntent);
                }catch (Exception e){
                    String q="";
                }
            }
        });

        return convertView;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.child, null);
        }

        ((CheckedTextView) convertView).setText(parentItems.get(groupPosition));
        ((CheckedTextView) convertView).setChecked(isExpanded);


        return convertView;
    }


    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return ((ArrayList<String>) childtems.get(groupPosition)).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public int getGroupCount() {
        return parentItems.size();
    }

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }


}

将上下文发送到适配器并使用它:

  class MainActivity extends Activity {

        ExpandableAdapter adapter = new ExpandableAdapter(activity,parent,children);

 }

class ExpandableAdapter ...
{
   public ExpandableAdapter(Context context...)
   {
    mContext = context;

   }


 }

Context mContext;
mContext.openFileOutput

你也可以使用你发送给适配器的activityclass