1

我在网格视图中有一个 ItemClickListener。但是我的 itemclicklistener 没有被调用。网格视图的项目单击没有活动

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

        vi = inflater.inflate(R.layout.home, container, false);

        Button startdialog = (Button) vi.findViewById(R.id.btnCreateDialog);
        startdialog.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent startdialog = new Intent(getActivity(),
                        start_dialog.class);
                startActivity(startdialog);
            }
        });

        Button iv = (Button) vi.findViewById(R.id.btnMoreDialog);
        iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupMenu homepopup = new PopupMenu(getActivity(), v);

                MenuInflater inflater = homepopup.getMenuInflater();

                inflater.inflate(R.menu.moredialog, homepopup.getMenu());

                homepopup.show();

            }
        });

        PremiumgridView = (StaggeredGridView) vi
                .findViewById(R.id.premiumstaggeredGridView);


        new Dialogs().execute(urls);

        return vi;
    }

    private class Dialogs extends AsyncTask<String[], Void, String[]> {
        @Override
        protected String[] doInBackground(String[]... params) {

            return params[0];
        }

        protected void onPostExecute(String[] result) {

            int premiummargin = getResources().getDimensionPixelSize(
                    R.dimen.margin);
            PremiumgridView.setItemMargin(premiummargin);
            PremiumgridView.setPadding(premiummargin, 0, premiummargin, 0);

            final StaggeredAdapter premiumadapter = new StaggeredAdapter(
                    vi.getContext(), R.id.photoimageview, result,
                    R.layout.row_staggered_demo);

            PremiumgridView.setAdapter(premiumadapter);

            premiumadapter.notifyDataSetChanged();

            premiumadapter.onClick(vi);
            PremiumgridView.setOnItemClickListener(new OnItemClickListener() {

                @Override
            public void onItemClick(StaggeredGridView parent, View view,
                    int position, long id) {
                     String item = premiumadapter.getItem(position).toString();
                      Toast.makeText(getActivity(), premiumadapter.getItem(position), Toast.LENGTH_SHORT).show();
                  // Toast.makeText(getActivity(), "You have chose: "+ item, Toast.LENGTH_LONG).show();

            }});


        }

        @Override
        protected void onPreExecute() {

        }
    }

请问有人吗?

谢谢,

4

2 回答 2

1

通过从xml中删除按钮解决了这个问题。可点击项目中不能有其他可点击项目。参考OnItemClickListener 未在 Android GridView 上触发

于 2013-07-13T07:10:26.233 回答
0

它会崩溃吗?如果是,请始终向我们提供 Stacktrace/Logcat。

据我所知,除了 UI-Thread 之外,不可能直接从任何 Thread 中更改界面 - 您可以尝试Handler或使用this

编辑: OnPostExecute 实际上是在 UI 线程上调用的,所以这不是解决这个问题的方法。(见这里

于 2013-07-12T07:30:56.120 回答