1

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.

John K
  • 371
  • 5
  • 26
  • You have to implement your own `RecyclerView.Adapter` which will be obtaining data from connection and setting them to views. Just find some simple adapter example e. g. adapter which is using an array as underlying data source and replace it by your connection-based data source. – matoni Jul 25 '17 at 12:51
  • i have yet a RecyclerView.Adapter – John K Jul 25 '17 at 13:29
  • "... app will load number of recyclerView ..." so you have more recyclerviews in your activity? why are you using more recyclerviews? just use one and fill the content by data – matoni Jul 25 '17 at 13:44
  • 1
    @matoni nah with more recyclerViews i mean more boxes – John K Jul 25 '17 at 13:59
  • 1
    here is a detailed explanation how to implement adapter [recyclerview tutorial](https://stackoverflow.com/questions/30398247/how-to-filter-a-recyclerview-with-a-searchview#answer-30429439) (just ignore search functionality) – matoni Jul 25 '17 at 14:03

1 Answers1

2

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

Mahesh Gawhane
  • 348
  • 3
  • 20