我正在尝试为andoid创建一个应用程序,以显示体育联盟中的排名。到目前为止,我已经建立了一个在线数据库并将其连接到php。现在我需要一些帮助将所有内容连接在一起以文本视图(或任何可以按照描述工作的方式)。
我的在线数据库如下所示: http://scoreboardbaza.site88.net/premierleague.php
我的php文件:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT mesto, ekipa, tekme, zmage, izenaceno, porazi, dosezenigoli, dobljenigoli, golrazlika, tocke FROM premierleague";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Mesto</th><th>Ekipa</th><th>Tekme</th><th>Zmage</th><th>IzenaÄeno</th><th>Porazi</th><th>Doseženi goli</th><th>Prejeti goli</th><th>Gol razlika</th><th>ToÄke</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td align='center'>".$row["mesto"]."</td><td>".$row["ekipa"]." </td><td align='center'>".$row["tekme"]."</td><td align='center'>".$row["zmage"]."</td><td align='center'>".$row["izenaceno"]."</td><td align='center'>".$row["porazi"]."</td><td align='center'>".$row["dosezenigoli"]."</td><td align='center'>".$row["dobljenigoli"]."</td><td align='center'>".$row["golrazlika"]."</td><td align='center'>".$row["tocke"]." </td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
我的“PremierLeagueLestvica.java”看起来像这样:
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
public class PremierLeagueLestvica extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_premier_league_lestvica);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_premier_league_lestvica);
//Gumb NAZAJ zav začetni zaslon
Button btnNazaj = (Button)findViewById(R.id.btnNazaj);
btnNazaj.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(PremierLeagueLestvica.this, NogometActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_premier_league_lestvica, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
xml文件“activity_premier_league_lestvica.xml”:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Premier League"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#ffffffff"
android:textSize="45dp"
android:gravity="center"
android:textIsSelectable="false"
android:background="@drawable/back"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nazaj"
android:id="@+id/btnNazaj"
android:background="@drawable/back"
android:textColor="#ffffffff"
android:elegantTextHeight="false"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/textView"
android:layout_alignEnd="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textPL"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/btnNazaj"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />