简体   繁体   English

如何在Android TextView中显示PHP内容?

[英]How to show a PHP content in a Android TextView?

I'm new here and yet green in android as a programmer. 我是新来的,但在Android中却是绿色程序员。 And unfortunately I didn't had success in my searches :( 不幸的是,我的搜索没有成功:(

I wanna show in a TextView all the content of a index.php file. 我想在TextView中显示index.php文件的所有内容。 Is that possible? 那可能吗?

My code till now: 到目前为止,我的代码:

res/layout/activity_php.xml RES /布局/activity_php.xml

<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>

java/projectName/functions/PhpActivity java / projectName / functions / PhpActivity

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();
            }
        });

    }
}

the path to the php file is something like this: http://www.myDomainName.com/chat/log/index.php php文件的路径如下所示: http : //www.myDomainName.com/chat/log/index.php

and add the 并添加

 <uses-permission android:name="android.permission.INTERNET" />

on app/manifests/AndroidManifest.xml file app / manifests / AndroidManifest.xml文件上

The PHP have some HTML content and results of MySQL querys 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");
?>

If possible and answer with explanation, I'm a newbie. 如果可能,并给出解释,我是新手。 Thank you in advance! 先感谢您!

You can simply use Webview and load your url like this 您可以简单地使用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");

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM