• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to get data from SQL table when clicked on recyclerview item?

Hi.

I have one problem.

I made recyclerview and I populate it with information from database.
I also made onclicklistener for every recyclerview item.

I do not know how to get data from database when I click on an item in recyclerview list.

Example: I need to get location from database and return it as a string,but for every item in recyclerview that location is different.
 
Okay.

I have this code in my activity where lessons are listed in recyclerview like this.


Java:
if(oblast == 1)
        {
            lekcijalist = database.getElektrostatikaLekcije();


            lekcijaAdapter = new LekcijaAdapter(this,lekcijalist);
            RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
            recyclerView.setLayoutManager(mLayoutManager);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
            recyclerView.setAdapter(lekcijaAdapter);

            lekcijaAdapter.setOnItemClickListener(new LekcijaAdapter.ClickListener() {
                @Override
                public void onItemClick(int position, View v) {

                    Toast toast = Toast.makeText(context,"ID Lekcije u bazi: " + position,Toast.LENGTH_SHORT);
                    toast.show();


                }

                @Override
                public void onItemLongClick(int position, View v) {

                }
            });

        }


How I can get data of clicked item in recyclerview from database
 
There's an article here which takes you through building a nice application architecture, with observable data, linked to a RecyclerView.
 
You read and understood all that lot in less than 20 minutes.
Really?
That tutorial shows you how to construct an app which displays data from a database table, using a RecyclerView, with a completely modular and clean architecture.
Open your mind and consider different ways to achieve what you're trying to do.
 
Back
Top Bottom