Android listview onitemclicklistener does nothing

I have a listfragment used as a tab. I am trying to use onitemselectedlistener on my listview, which must start another activity and add specific extra content to the intention according to the selected item. I am using the following code:

View rootView = inflater.inflate(R.layout.fragment_priority_tab, container, false);
    ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    List<String> printedList = calculateProportions();
    ArrayAdapter<String> expensesAdapter = new ArrayAdapter<>(mContext,
            android.R.layout.simple_list_item_1, printedList);
    listView.setAdapter(expensesAdapter);
    listView.setClickable(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            Intent intent = new Intent(mContext, ListPriority.class);
            switch (position) {
                case 0:
                    intent.putExtra("priority", "low");
                    startActivity(intent);
                    break;
                case 1:
                    intent.putExtra("priority", "med");
                    startActivity(intent);
                    break;
                case 2:
                    intent.putExtra("priority", "high");
                    startActivity(intent);
                    break;
                case 3:
                    intent.putExtra("priority", "obsolete");
                    startActivity(intent);
                    break;
            }
        }
    });

I didn't have any errors or warnings, but my activity didn't start. When I debugged the application and clicked on any project, I didn't even reach the breakpoint

My XML listview:

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

My java code is in oncreateview in listfragment

resolvent:

Listfragment handles its own onitemclicklistener. Instead of setting the listener, override onlistitemclick()

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>