Search code examples
javaandroidandroid-recyclerviewtcpclienttcpserver

How do i set data to every single recyclerView?


About my app:

I've made an app that at the start is receiving from a TCP Server to a TCP Client number of cash registers conected to the network, after i open another activity called "help" my TCP Server is receiving other data from the Server like the device ID and amount of receipts got in it.

Question?

For now when i open the help activity app will load number of recyclerView that equals to the number of cash registers sent by the Server and it apply to ALL the recyclerViews same amount of receipts and the ID, now what i have to do it's to assign the data to single recyclerView.

Example

App is starting, Server is sending number of 5 devices, i'm opening the help activity and asking again for data from the Server, the server is sending 0#17#190 (0 staying for cash register active 17 for receipts and 190 for money in it ) and i have to apply this to just 1ST recyclerView in the list and ask the Server again for the data of the 2nd..3rd... cash registers.

Pic

Here is my MainActivity code where i connect to the Server and get the data:

     public static class ConnectTask extends AsyncTask<String, String, Client> {

    @Override
    protected Client doInBackground(String... message) {


        client = new Client(new Client.OnMessageReceived() {
            @Override

            public void messageReceived(String message) {

                publishProgress(message);

            }
    });
        client.run();

        return null;
    }

    @Override
    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);

        if(MainActivity.active){
            msgServer.setTextColor(Color.parseColor("#00FF00"));
            msgServer.setText("ONLINE");

            SelfNumber = values[0];
        }
        if(help.active){
            StringTokenizer stringTokenizer = new StringTokenizer(String.valueOf(values[0]),"#");
            status = stringTokenizer.nextToken();
            receipt = stringTokenizer.nextToken();
            eur = stringTokenizer.nextToken();

            for(int i=0; i< Integer.valueOf(SelfNumber); i++){
                help.adapter = new SelfAdapter(("CASSA SELF N°" + Integer.toString(i+1)),"EUR: " + eur,"SC: " + receipt,help.img);
                help.selfList.add(help.adapter);
                help.adapterView.notifyDataSetChanged();
            }

        }

    }
}

While in help activity i just recall Client connection with:

MainActivity.startConnection.removeCallbacks(MainActivity.runnableConnection) 

MainActivity.startConnection.postDelayed(MainActivity.runnableConnection,5000);

MainActivity.startMessage.removeCallbacks(MainActivity.runnableMessage);

MainActivity.startMessage.postDelayed(MainActivity.runnableMessage,5500);

If someone need more code i'll be able to post more.


Solution

  • please check the sample example for recyclerview here https://www.simplifiedcoding.net/android-recyclerview-and-cardview-tutorial/