无法解析符号“LayoutInflater inflater,ViewGroup容器”

时间:2015-09-21 07:40:05

标签: java android

我有一个方法“displayEventInvitationList”,当我在“onoptionsitemselected”中调用“displayEventInvitationList(LayoutInflater inflater,ViewGroup container)”之类的方法时,参数“inflater,container”我得到错误无法解析符号“inflater,container “。请告诉我代码如何解决这个问题。

 public boolean onOptionsItemSelected(MenuItem item) {
        Log.d("onOptionsItemSelected", "yes");

        switch (item.getItemId()) {
            case R.id.all:
                //I am getting "cannot resolve symbol" here  
                displayEventInvitationList(LayoutInflater inflater,ViewGroup container); 
                return true;
            case R.id.event:
                displayEventList();
                return true;
            case R.id.invitation:
                displayInvitationList();
                return true;
            default:
                return super.onOptionsItemSelected(item);

        }

    }
public View displayEventInvitationList(LayoutInflater inflater, ViewGroup container) {
        context = getActivity().getApplicationContext();
        view = inflater.inflate(R.layout.chatwindow_tab, container, false);
        sharedpreferences = context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME,
                Context.MODE_PRIVATE);
        DatabaseHelper dbHelper = new DatabaseHelper(context);
        final UserMO userMO = dbHelper.getRingeeUserData(1);
        new AsyncTask<Void, Void, List<EventMO>>() {
            @Override
            protected List<EventMO> doInBackground(Void... arg0) {
                eventMOs = gson.fromJson(eventDelegates.getAllEventFromUser(userMO, context), new TypeToken<List<EventMO>>() {
                }.getType());
                invitationMOs = gson.fromJson(eventDelegates.getAllEventForUser(userMO, context), new TypeToken<List<EventMO>>() {
                }.getType());
                List<EventMO> groupEventInvitesList = new ArrayList<>();

                for (EventMO eventMO : eventMOs) {
                    groupEventInvitesList.add(eventMO);

                }
                for (EventMO eventMO : invitationMOs) {
                    groupEventInvitesList.add(eventMO);

                }

                return groupEventInvitesList;

            }

            @Override
            protected void onPostExecute(List<EventMO> groupEventInvitesList) {
                groupEventMoList = groupEventInvitesList;
                chatDisplayAdapter = new ChatDisplayAdapter();
                groupEventView.setAdapter(chatDisplayAdapter);
                groupEventView.setAdapter(dataAdapter);
                groupEventView.setItemsCanFocus(true);
                groupEventView.setTextFilterEnabled(true);
                groupEventView.setOnItemClickListener(groupEventView.getOnItemClickListener());
            }
        }.execute(null, null, null);
        return view;
    }

1 个答案:

答案 0 :(得分:0)

根据我的评论,问题是您没有为方法调用提供任何参数:

displayEventInvitationList(LayoutInflater inflater,ViewGroup container);

如果您要扩展Fragment来创建此类,那么一个选项是存储来自LayoutInflater的{​​{1}}和ViewGroup个参数。您可以将这些保存到类变量中,并在onCreateView中使用它们。

onOptionsItemSelected

如果不这样做,您将需要找到一种方法来访问适当的//Class Variables LayoutInflater inflater; ViewGroup container; //... @Override public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.inflater = inflater; this.container = container; } //And in onOptionsItemSelected... displayEventInvitationList(inflater, container); LayoutInflater对象以用作参数。 ViewGroup相对简单(即LayoutInflater),但您需要访问正确的LayoutInflater li = LayoutInflater.from(context);以获取要呈现的任何布局和小部件。

此外,构建方法调用的方式意味着在涉及方法调用/声明时,您不了解Java基础知识,这对于理解Android非常重要。所以,我还建议你花些时间熟悉它们。