android – Update RecyclerView Adapter in a Fragment from an Activity

I am making a mobile application on Android. I have a TabLayout with two tabs and each one is a fragment. In the first fragment I have a RecyclerView that I would like to update.

At MainActivity, I have an AlertDialog to enter data and save it locally, then the idea is to update the RecyclerView Adapter to present the new data.

MainActivity

public class MainActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewPager = (ViewPager) findViewById(R.id.view_pager);
        setupViewPager(viewPager);

        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);
    }

    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(new StudentsFragment(), getString(R.string.tab_students));
        adapter.addFragment(new ReportsFragment(), getString(R.string.tab_reports));
        viewPager.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.add_student:
                addStudent();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private void addStudent() {
        final AlertDialog dialog;
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        LayoutInflater inflater = this.getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.dialog_add_student, null);
        dialogBuilder.setView(dialogView);

        final EditText nameEditText = dialogView.findViewById(R.id.nameEditText);
        Button addButton = dialogView.findViewById(R.id.addButton);

        dialog = dialogBuilder.create();
        dialog.show();

        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // Aquí guardo el dato localmente

            }
        });
    }
}

ViewPagerAdapter

public class ViewPagerAdapter extends FragmentPagerAdapter {

    private final List mFragmentList = new ArrayList<>();
    private final List mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }

}

RecyclerViewAdapter

public class RecyclerViewAdapter extends RecyclerView.Adapter {

    private Context mContext;

    public RecyclerViewAdapter(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    public RecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.student_item, parent, false);
        RecyclerViewAdapter.ViewHolder viewHolder = new RecyclerViewAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        String name = studentList.get(position).getName();
        holder.nameTextView.setText(name);
    }

    // Método para actualizar el Adapter
    public void updateRecyclerViewAdapter(List studentList) {
        this.studentList = studentList;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return studentList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private View mView;
        private TextView nameTextView;

        public ViewHolder(View itemView) {
            super(itemView);

            mView = itemView;
            nameTextView = itemView.findViewById(R.id.nameTextView);
        }

    }

}

StudentsFragment

public class StudentsFragment extends Fragment {

    public StudentsFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_student, container, false);

        final FragmentActivity fragmentActivity = getActivity();
        final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(fragmentActivity, LinearLayoutManager.VERTICAL, false);
        recyclerView.addItemDecoration(new DividerItemDecoration(fragmentActivity, DividerItemDecoration.VERTICAL));
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setHasFixedSize(true);

        recyclerView.post(new Runnable() {
            @Override
            public void run() {
                final RecyclerViewAdapter adapter = new RecyclerViewAdapter(fragmentActivity);
                fragmentActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        recyclerView.setAdapter(adapter);
                    }
                });
            }
        });

        return view;
    }

}

I only have the method to update the Adapter inside the RecyclerViewAdapter. But how can I call it from MainActivity?

My goal is, when the user opens the AlertDialog from MainActivity and enters a data, after saving it, update the RecyclerViewAdapter to present the new data.

Pure SSD hosting 👍20 years of experience ✔️ Free migration 🌓99.99% Activity time ☁️CloudLinux 💲1.5 $ / year

Our goal is to provide our clients with the best possible shared hosting experience, our servers are hosted in Premium locations that offer high quality bandwidth, pure SSD storage and solid uptime …

More than 20 years of experience supporting shared hosting clients and can help you with all hosting needs and address your concerns in a very professional and friendly way.

With our 60-day money back guarantee (no questions asked), you can't go wrong with us! …

Our support strengths: –

– More than 20 years of experience in the field of web hosting and industry …
– I have been working with cPanel as part of your team since day one …
– Solid work experience with hundreds of frameworks such as: Drupal, WordPress, OpenCart, Magento, WHMCS, HostBill, etc.
– Made more than 20,000 hours of telephone support in the field of web hosting …
– Migrated more than 10,000 websites to similar and different environments …
– We have personal contacts with industry experts even before they became industry experts …
– Training of people to become better hosts since 2001 …

Service Highlights: –

* CPanel free and Softaculous
* CloudLinux with CageFS
* 99.99% uptime guarantee
* 24×7 Premium Support
* 100% pure SSD storage
* Free SSL certificates
* Monthly renewals
* 1 Gbps Internet port
* Daily / weekly / monthly backups
* 1 year backup retention
* Free instant setup
* Free migration
* Large resource group
* Optional free domain
* 60 day refund policy

Usage Code: WELCOME15 Arrive –fifteen% Discount on your first subscription period …

To opt. Dedicated IPv4 @ $ 0.99 / month only! …

Check our cheap TLDs (.com / net / org / biz / .info) $ 5.89/year !!.

Plans: –

Pluto
Pure SSD: 250 MB
Bandwidth: Unlimited
Domains: one
E-mail accounts: Unlimited
Databases: one
Free domain: N / A
Prepare: Instant
Only: $ 1.5/Year
Instant implementation

Mercury
Pure SSD: 500 MB
Bandwidth: Unlimited
Domains: two
E-mail accounts: Unlimited
Databases: two
Free domain: N / A
Prepare: Instant
Only: $ 3/Year
Instant implementation

Mars
Pure SSD: 1000 MB
Bandwidth: Unlimited
Domains: 3
E-mail accounts: Unlimited
Databases: 3
Free domain: N / A
Prepare: Instant
Only: $ 3/ Semi annually
Instant implementation

Venus
Pure SSD: 2000 MB
Bandwidth: Unlimited
Domains: 4
E-mail accounts: Unlimited
Databases: 4
Free domain: N / A
Prepare: Instant
Only: $ 3/Quarterly
Instant implementation

land (Best value)
Pure SSD: 4500 MB
Bandwidth: Unlimited
Domains: Unlimited
E-mail accounts: Unlimited
Databases: Unlimited
Free domain: Yes
Prepare: Instant
Only: $ 1.5/Month
Instant implementation

Neptune
Pure SSD: 6000 MB
Bandwidth: Unlimited
Domains: Unlimited
E-mail accounts: Unlimited
Databases: Unlimited
Free domain: Yes
Prepare: Instant
Only: $ 3/Month
Instant implementation

Uranus
Pure SSD: 8000 MB
Bandwidth: Unlimited
Domains: Unlimited
E-mail accounts: Unlimited
Databases: Unlimited
Free domain: Yes
Prepare: Instant
Only: $ 4/Month
Instant implementation

Saturn
Pure SSD: 12000 MB
Bandwidth: Unlimited
Domains: Unlimited
E-mail accounts: Unlimited
Databases: Unlimited
Free domain: Yes
Prepare: Instant
Only: $ 6/Month
Instant implementation

Jupiter
Pure SSD: 25000 MB
Bandwidth: Unlimited
Domains: Unlimited
E-mail accounts: Unlimited
Databases: Unlimited
Free domain: Yes
Prepare: Instant
Only: $ 10/Month
Instant implementation

We do not accept: –

Adult content
Game
Impersonation
Fraud / Scam Schemes
Unwanted mail

Stay in contact:
E-mail: admin@hypervmart.com
Skype: hypervmart@outlook.com
Ticket: Send ticket
Facebook | Twitter

Chrome incognito activity monitoring: superuser

Is there a way for my employer to monitor Chrome’s incognito activity if I’m out of your network, sign in with my Google G Suite account on Chrome (not on any website) and use my home computer? (purchased and configured by me)

I'm pretty sure (75 percent or so) that they can't.

I have researched enough about this, and although I have not found anything that contradicts my hypothesis, I would like a confirmation.

Well, then I researched Enterprise Chrome Management (My browser is not managed, according to chrome: // management), Azure Active Directory (not connected according to Settings> Accounts> Access to work or school, and the command dsregcmd /status) and Active Directory (with Windows 10 Home).

Additional details about my computer and Chrome:
latest version of Chrome
Sign in to Chrome with the G Suite account (example@example.com)
Windows 10 1903
The computer is my property.
The Microsoft account I signed in to is my property and is set up by me.

I prefer a detailed explanation of why, if you don't mind.

Thanks in advance.

Android development: how to get DecorView from another activity of the current one?

I have two activities The activity below can be seen through.
I use a blurry library that takes views above and below. Blurred view of 500px, to be precise.

I want to get the first activity as a view along with the second and go to the blurred view.

How can I do it?

java – Animation shared between Android Activity

Thank you for contributing to Stack Overflow in Portuguese!

  • Make sure answer the question. Enter details about your solution and share what you found.

But avoid

  • Request clarification or details about other answers.
  • Make statements based only on your opinion; Point out references or previous experiences.

For more information, see our tips on how to write good answers.

network: Google’s suspicious activity warning persists for 4 days even though I say I recognize it, does this indicate an additional security issue?

Four days ago I received a warning of suspicious activity from Google that was activated when I signed in from a location I don't use frequently. I accepted the offer to see the activity and acknowledged that I recognized it. This usually causes the warning to disappear.

However, in this case, every time I log in again in the last four days, A red warning bar appears at the top of a Google page with a login.

warning

When i click Review your recent activity The gray critical security alert box appears with a white box on it that says "You have already answered that you recognize this activity" followed by two options Change reply Y OK.

Of course, I click "Accept" each time because I don't want to change my answer and run the risk of blocking my account.

QUESTION: Does this behavior indicate that there is another security problem that I do not know? What would happen if I clicked instead? Change reply? Right now I have two factors disabled, so I am very worried about being blocked. Is there any other problem I can look for in some way?

  • incognito mode macOS and Chrome

I should point out that in the last weeks I received two dialogues from Google when I started a search, to verify that it was not a robot, due to the "unusual traffic of (my) computer network". (also shown below)

That happened on a shared WiFi connection using a DSL line.


warning


warning

web development – Looking for comments – Activity time monitoring

After Pingdom discontinued its free plan, we decided to create an application that would be the free replacement, providing all the features they used to do without incomplete upgrade paths and everything …
1 minute checks, blacklist and SSL monitoring, root cause analysis, integrations, reports and all … the full list is here uptimezen.com

We are aware that there are many like Pingdom out there. However, our goal is to make webmasters' lives easier at least make money stay in your pocket when it comes to monitoring the status of your website. (and not remove features and force them to update …)

The question comes at this point:
We want to get the ideas of other webmasters to decide what to code next so that our free application replaces your current solution (if any) of paid uptime. What do you need most? We are looking for ideas to implement and the central idea is to make life easier for webmasters …

Thanks in advance…

How Facebook Ads in an online virtual machine without raising suspicious activity banners

Hello,

I am new to accommodation in general and I am trying my best to get an overview.

This is what I am trying to achieve:

Run Facebook ads on a virtual machine hosted online with a dedicated Hong Kong IP address without raising any indicators of suspicious activity in FB.

For my work, I need to run Facebook ads, but I also need to travel a lot to conferences and meet with clients. It’s crucial to sign in to the FB ad manager always from the same location
in order to avoid safety stops due to suspicious activities. So far I did it through TeamViewer when I was traveling. But that is not a good long-term solution for me.

I know that some people are solving this by running FB on a virtual machine that is hosted online. Then I thought I tried the same.

I just started the investigation phase.

I know that somehow I need dedicated vps hosting and that I can order that, but I also need to make sure that FB does not detect it (although it is not prohibited by its terms and conditions) because the bots would probably mark my accounts if they notice that I am not running in A real computer.

Maybe someone can share some experience or give concrete advice on how to realize that.

Thank you

dnd 5e: purchase of a magic item Inactivity activity: opportunity to buy later

I am using the downtime activity rules in the Xanathar Everything Guide and I was wondering if there are rules (or suggested approaches) to allow my players to buy one of their magical items discovered at a later date.

For example, one of the players rolled down a knight's saddle, but none of the group members have a horse. Do the rules allow the player to track the merchant at a later date to buy the item? Or is it more a discretionary decision of a DM?