Rishka
Rishka

Reputation: 423

Infinite scroll with clickable listView

I've got a task - to create an infinite scroll of ListView. And ListView elements must be clickable (it's a list of articles and when u click on it - it openes article fully). Currently, if I try to handle touch events it has conflits with onClickListener that attached to ListView elements. How can I do this?

Here's my onClickListener:

        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
        }

        //Set event on list item click
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent myIntent = new Intent(mContext, ShowActivity.class);

                if (mType.equals("news")) {
                    myIntent.putExtra("id", itemsNews.get(mPosition).getId());
                }
                if (mType.equals("author")) {
                    myIntent.putExtra("id", itemsAuthor.get(mPosition).getId());
                }
                if (mType.equals("special")) {
                    myIntent.putExtra("id", itemsSpecial.get(mPosition).getId());
                }
                myIntent.putExtra("type", mType);
                mContext.startActivity(myIntent);
            }
        });

I've tried to attach onScrollListener but my converView doesn't know such method. Any help would be appreciated! I'll add any code you'd ask for.

Upvotes: 2

Views: 315

Answers (1)

Kavis
Kavis

Reputation: 98

Add OnItemClickListener for listview and start the new activity from there.

listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick (AdapterView < ? > parent, View view,int position,long id){

            Intent myIntent = new Intent(mContext, ShowActivity.class);

            switch (mType[position]) {
                case "news":
                    myIntent.putExtra("id", itemsNews.get(position).getId());
                    break;
                case "author":
                    myIntent.putExtra("id", itemsAuthor.get(position).getId());
                    break;

                case "special":
                    myIntent.putExtra("id", itemsSpecial.get(position).getId());
                    break;
            }

            myIntent.putExtra("type", mType);
            mContext.startActivity(myIntent);

        }
    });

Upvotes: 1

Related Questions