asifa
asifa

Reputation: 771

OnItemClickListener is not being called

I have an ItemClickListener in a gridview. But my itemclicklistener is not being called. There is no activity on item click of the gridview

@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() {

        }
    }

Anyone please?

Thanks,

Upvotes: 1

Views: 284

Answers (2)

asifa
asifa

Reputation: 771

Solved the problem by removing the button from the xml. Clickable item cannot have another clickable item inside it. Reference OnItemClickListener Not Triggered on Android GridView

Upvotes: 1

Benjamin Schwalb
Benjamin Schwalb

Reputation: 1134

Does it crash? If yes, always provide us with the Stacktrace/Logcat.

As far as I know, it´s impossible to directly change the interface from within any Thread other than the UI-Thread - you could either try Handler or use this.

EDIT: OnPostExecute is actually called on the UI-Thread, so this is not a solution for this problem. (see here)

Upvotes: 0

Related Questions