简体   繁体   English

我正在创建一个Android应用,我希望多个人可以访问相同的号码,并能够通过两个按钮更改该号码

[英]I am creating an android app and I want multiple people to have access to the same number and be able to change that number with two buttons

I am creating an app where people report whether or not they have the flu that week. 我正在创建一个应用程序,人们可以在该应用程序中报告当周是否患有流感。 I already have the code that allows me to be able to add to the number of people who do have the flu and the number of people who don't have the flu by pressing buttons. 我已经有了代码,可以通过按按钮将确实患有流感的人数增加到没有流感的人数。 It then creates a percentage of people who have the flu based on that data. 然后根据该数据创建一定比例的流感患者。 But whenever I close out of the app, all of the data goes away. 但是,每当我关闭应用程序时,所有数据都会消失。 The same data also won't be able to be accessed by the other people with the app. 使用该应用程序的其他人也将无法访问相同的数据。 Here is the code for the app. 这是该应用程序的代码。

public void fluButton()
{
    Button hasFluButton = (Button)findViewById(R.id.fluButton);

    hasFluButton.setOnClickListener(
            new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    TextView t1 = (TextView)findViewById(R.id.influenzaPercent);
                    NumberFormat defaultFormat = NumberFormat.getPercentInstance();
                    defaultFormat.setMinimumFractionDigits(2);

                    numPeopleWFlu += 1;

                    percentFlu = ((double)numPeopleWFlu) / (numPeopleWOFlu + numPeopleWFlu);
                    String percent = defaultFormat.format(percentFlu);
                    t1.setText(percent + " of people have had the flu this week.");
                }
            }
    );
}

public void noFluButton()
{
    Button hasNoFluButton = (Button)findViewById(R.id.noFluButton);

    hasNoFluButton.setOnClickListener(
            new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    TextView t1 = (TextView)findViewById(R.id.influenzaPercent);
                    NumberFormat defaultFormat = NumberFormat.getPercentInstance();
                    defaultFormat.setMinimumFractionDigits(2);

                    numPeopleWOFlu += 1;

                    percentFlu = ((double)numPeopleWFlu) / (numPeopleWOFlu + numPeopleWFlu);
                    String percent = defaultFormat.format(percentFlu);
                    t1.setText(percent + " of people have had the flu in missouri this year.");
                }
            }
    );
}`.

This answer will only provide you with a very vague solution as your question is broad. 由于您的问题很广泛,此答案只会为您提供一个非常模糊的解决方案。

Here's what you need to do, you need to rent a server and put all the data to that server. 这是您需要做的事情,需要租用服务器并将所有数据放入该服务器。

Why do you need a server? 为什么需要服务器? Because you want lots of people to access the data as the same time. 因为您希望很多人同时访问数据。 If you save the data to your app's SharedPreferences or something local, other people won't be able to get it. 如果您将数据保存到应用程序的SharedPreferences或本地文件中,则其他人将无法获取它。

So now you have a server, in your app, you retrieve the data from the server at the start of your app. 因此,现在您在应用程序中有了一个服务器,您可以在应用程序启动时从服务器检索数据。 There are lots of external libraries out there that can help you fetch something from the internet. 那里有很多外部库可以帮助您从Internet上获取内容。

After you retrieved the data, you display it in some views and BOOM! 检索数据后,可以在某些视图和BOOM中显示它! You did the first part. 您做了第一部分。 The second part is to save the data to the server. 第二部分是将数据保存到服务器。 When the user taps on a button or something, you save the data. 当用户点击按钮或其他内容时,您将保存数据。

Sounds easy, huh? 听起来很容易,对吧?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:UIL我希望能够多次加载同一张图片 - Android: UIL I want to be able to load the same image multiple times 我在 ArrayList 中有 9 个 JButton。 但无论如何我都无法更改按钮的标签,,, - I have 9 JButtons in the ArrayList . But I am not able to change the Lable of the Buttons in any event,,, 我想将数字拆分为一个数字并将其更改为android中的二进制 - I want to split a number into single digit and change it into the binary in android 我正在创建的该程序必须检查一个数字是否为另一个数字的倍数 - This program that I am creating has to check to see if one number is a multiple of another number 我如何让 2 个人访问同一个数据库(android app dev)? - How do i make 2 people access the same db (android app dev)? 如何在java中将字符串转换为数字? 但我不是在寻找 hashCode,因为它不会给出唯一编号。 至少我想要同样的数学逻辑 - How to convert string to number in java ? But i am not looking for hashCode as it wont give unique number. at least i want math logic for same 我有以下数据集,我想根据重复次数将此数据更改为目标输出数据集 - I have below dataset and i want to change this data into target output datatset on the basis of number of repetitions 我正在尝试使用休眠envers连接2个表以具有相同的转速编号? - I am trying to connect 2 tables to have same rev number using hibernate envers? 我想使用Java获取我的Android设备的Build Number,Android版本。 我使用以下代码: - I want to get Build Number, Android Version of my Android device using Java. I am using the following code: JAVA:没有得到我想要的小数位数 - JAVA: Am not getting the number of decimal points I want
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM