我是新来的,但在Android中却是绿色程序员。 不幸的是,我的搜索没有成功:(
我想在TextView中显示index.php文件的所有内容。 有可能吗?
到目前为止,我的代码:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/colorPrimaryDark" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_back"
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="@drawable/ic_back" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="center"
android:text="@string/title_php"
android:gravity="center_vertical"
android:textSize="20dp"
android:textColor="@color/colorAccent" />
</LinearLayout>
<RelativeLayout
android:id="@+id/view_php"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" >
<TextView
android:id="@+id/view_php_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Here I wanna see the index.php content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/btn_php"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:text="Show content"
android:textColor="@color/colorPrimaryDark"
android:background="@color/colorAccent"
android:textSize="8dp" />
</RelativeLayout>
</RelativeLayout>
package com.packageName.projectName;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class PhpActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_php);
Button btnBack = findViewById(R.id.btn_back);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent closeView = new Intent(PhpActivity.this, MainActivity.class);
startActivity(closeView);
finish();
}
});
Button btnPHP = findViewById(R.id.btn_php);
btnPHP.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Here I wanna put a trigger to start the process
Toast.makeText(TestaActivity.this, "Recieving", Toast.LENGTH_LONG).show();
}
});
}
}
php文件的路径如下所示: http://www.myDomainName.com/chat/log/index.php
并添加
<uses-permission android:name="android.permission.INTERNET" />
在 app / manifests / AndroidManifest.xml 文件上
PHP具有一些HTML内容和MySQL查询的结果
<?php
require_once("head.php");
require_once("loging-logic.php");
if(userLoged()) {
echo "<p class='text-success'>You're logged <?= userLogged() ?>. <a href='logout.php'>Logout?</a></p>";
} else {
header("Location: botID.php");
die();
}
?>
<h1>Log Page</h1>
<?php
require_once("conect.php");
require_once("body.php");
?>
<table class="table table-striped table-bordered">
<?php
$chatLogs = logList($conDB);
foreach($chatLogs as $log) :
?>
<tr>
<td><?= $device['devName'] ?></td>
<td><?= $type['id'] ?></td>
<td><?= substr($log['description'], 0, 60) ?></td>
<td>
<form action="delete.php" method="post">
<input type="hidden" name="id" value="<?=$type['id']?>" />
<button class="btn btn-danger">delete</button>
</form>
</td>
</tr>
<?php
endforeach
?>
</table>
<?php
require_once("foot.php");
?>
如果可能的话,并给出解释,我是新手。 预先谢谢你!
答案 0 :(得分:0)
您可以简单地使用Webview并像这样加载您的网址
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");