【问题标题】:I am trying to make a social media app. How do I connect my app to a mySql and, Xampp?我正在尝试制作一个社交媒体应用程序。如何将我的应用程序连接到 mySql 和 Xampp?
【发布时间】:2015-12-15 22:23:51
【问题描述】:

这是我的注册 java 代码:

public class Register extends AppCompatActivity {

Button bRR;
EditText etFN, etLN, etEmail, etUN, etPW, etRPW;
Spinner SMonth, SDay, SYaer;
TextView TVterms;
ArrayAdapter<CharSequence> adapter;


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

    //Button's go here
    bRR = (Button)findViewById(R.id.bRR);

    bRR = (Button)findViewById(R.id.bRR);
    bRR.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf"));
    //EditText's go here
    etFN = (EditText)findViewById(R.id.etFN);
    etLN = (EditText)findViewById(R.id.etLN);
    etEmail = (EditText)findViewById(R.id.etEmail);
    etUN = (EditText)findViewById(R.id.etUN);
    etPW = (EditText)findViewById(R.id.etPW);
    etRPW = (EditText)findViewById(R.id.etRPW);
    //Spinner's go here
    SMonth = (Spinner)findViewById(R.id.SMonth);
    SDay = (Spinner)findViewById(R.id.SDay);
    SYaer = (Spinner)findViewById(R.id.SYear);

    SMonth = (Spinner)findViewById(R.id.SMonth);
    adapter = ArrayAdapter.createFromResource(this, R.array.Month, R.layout.support_simple_spinner_dropdown_item);
    adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    SMonth.setAdapter(adapter);

    SDay = (Spinner)findViewById(R.id.SDay);
    adapter = ArrayAdapter.createFromResource(this, R.array.Day, R.layout.support_simple_spinner_dropdown_item);
    adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    SDay.setAdapter(adapter);

    SYaer = (Spinner)findViewById(R.id.SYear);
    adapter = ArrayAdapter.createFromResource(this, R.array.Year, R.layout.support_simple_spinner_dropdown_item);
    adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    SYaer.setAdapter(adapter);
    //TextView's go here
    TVterms = (TextView)findViewById(R.id.TVterms);
}
public void onSignUpClick(View v)
{
    if (v.getId() == R.id.bRR);
    {
        EditText fname = (EditText)findViewById(R.id.etFN);
        EditText lname = (EditText)findViewById(R.id.etLN);
        EditText uname = (EditText)findViewById(R.id.etUN);
        EditText email = (EditText)findViewById(R.id.etEmail);
        EditText pass1 = (EditText)findViewById(R.id.etPW);
        EditText pass2 = (EditText)findViewById(R.id.etRPW);

        String fnamestr = fname.getText().toString();
        String lnamestr = lname.getText().toString();
        String unamestr = uname.getText().toString();
        String emailstr = email.getText().toString();
        String pass1str = pass1.getText().toString();
        String pass2str = pass2.getText().toString();

        if (!pass1str.equals(pass2str))
        {
            //popup msg
            Toast pass = Toast.makeText(Register.this, "Password do not match!", Toast.LENGTH_SHORT);
            pass.show();

        }

    }
}

private void initTypeface() {

    Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    TextView tittleText=(TextView) findViewById(R.id.textView5);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.textView7);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.textView8);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.textView9);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.textView10);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.textView11);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.textView12);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.textView13);
    tittleText.setTypeface(myTypeface);

    myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
    tittleText = (TextView) findViewById(R.id.TVterms);
    tittleText.setTypeface(myTypeface);
}
}

我想存储 st 姓名、姓氏、用户名、电子邮件、出生日期和密码。我怎么做。我不能看这方面的教程,因为 ArrayList NameValuePair 已被弃用。

【问题讨论】:

    标签: java php android mysql


    【解决方案1】:

    首先,您需要创建以 JSON 格式发送输出的 php Web 服务。 在 android 应用程序中,我建议您使用 android volley 库。

    Volley 是一个 HTTP 库,它使 Android 应用程序的联网变得更容易,最重要的是,更快。 Volley 可通过开放的 AOSP 存储库获得。

    Read more about volley 这里还有关于 volley 和 mysql 连接的教程Volley mysql

    【讨论】:

    • 嘿,谢谢!但是我是android新手,所以我有点迷路了。你介意给我一个例子吗?这是我的电子邮件。 IsaacMedinaXbox360-live@hotmail.com。我真的很感激。谢谢 !!! @阿德南
    【解决方案2】:

    除了 Volley 库,你还可以使用 Retrofit 库并查看它的教程,this 教程真的很有帮助。这 2 个库是目前帮助服务器客户端通信的最常用的库。

    如果您不想使用 3rd 方库,可以在 Activity 中使用 AsyncTasks。如果您不熟悉 php mysql 集成,This 可能是一个很好的入门教程。 wamp 和 xammp 是类似的,你不必担心。

    【讨论】:

    猜你喜欢
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多