无法点击片段中的列表视图

时间:2018-12-24 06:52:36

标签: java android xml android-studio android-fragments

OnClickListner无法正常工作!

我的列表视图的每一行都有两个文本视图,它们位于 Fragmnet 中。我想传递不起作用的特定行onClick的ID。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_news, container, false);
    newsListView = (ListView) view.findViewById(R.id.news_list);
    newsListView.setClickable(true);
    newsList = new ArrayList<>();
    newsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0,View arg1, int position, long arg3) {
            System.out.println(position);

        }
    });
    loadNewsList();
    getActivity().setTitle("News");
    newsListView.setClickable(true);
    return view;
}

点击即可在控制台中获得

D/ViewRootImpl@19f3c4b[MusicActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 530252349440}
D/ViewRootImpl@19f3c4b[MusicActivity]: Relayout returned: oldFrame=[0,0][1080,1920] newFrame=[0,0][1080,1920] result=0x1 surface={isValid=true 530252349440} surfaceGenerationChanged=false
D/ViewRootImpl@19f3c4b[MusicActivity]: ViewPostImeInputStage processPointer 0
D/ViewRootImpl@19f3c4b[MusicActivity]: ViewPostImeInputStage processPointer 1

1 个答案:

答案 0 :(得分:2)

XML文件问题。请分享。