webview从另一个类的输入文本加载URL

时间:2017-05-09 09:01:08

标签: java android android-studio webview

我有两个类,MainActivity和InputAddress,如何从类InputAddress

加载url
view.loadUrl("here, im confused");

3 个答案:

答案 0 :(得分:1)

从inputAddrss发送数据,

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("url", YOUR_EDIT_TEXT.getText().toString());
startActivity(intent);

在MainActivity中接收数据,

String s = getIntent().getStringExtra("url");

然后加载到webview

view.loadUrl(s);

答案 1 :(得分:0)

您可以添加如下公共静态变量:

public class InputAddress {
  public static String address = "abc";
}

然后您可以像address一样访问MainActivity中的public class MainActivity { // ... public void onCreate(....) { Log.d("TAG", InputAddress.address); } } 变量:

$tp=6;
if (isset($_REQUEST['pag'])) $np=$_REQUEST['pag'];  else $np=1;
if (isset($_REQUEST['search']) && $_REQUEST['search']!='') {
    $filter1=$_REQUEST['search']; 
    $filter=$_REQUEST['search']; 
    $filter='%'.$filter.'%';
} else $filtro='';
$ini=($np-1)*$tp;
$fim=$np*$lp;
if ($filtro !='') 
    $sql="select *
from something
where and name like '$filter'
ORDER BY name DESC";
else
    $sql="select *
from something
ORDER BY name DESC";
$res=mysql_query($sql);
$nr=mysql_num_rows($res);
$qp=$nr/$tp+1;
mysql_free_result($res);

if ($filter !='')
    $sql="select *
from something
where name like '$filter'
ORDER BY name DESC  
limit $ini, $tp";
else
    $sql="select *
from something
ORDER BY name DESC
limit $ini, $tp";
$res=mysql_query($sql);
    ?>

<form align=center method='POST' action='index.php?cmd=list-something'>
            <h1 class="text-center">Search Something</h1>
            <div class="form-group">
                <div class="input-group">
                    <input class="form-control" type="text" name="search" placeholder="Search"/>
                    <span class="input-group-btn">
                        <button class="btn btn-success" type="submit"><span class="glyphicon glyphicon-search" aria-hidden="true"><span style="margin-left:10px;">Search</span></button>
                    </span>
                    </span>
                </div>
            </div>
</form>
<br><br> 

答案 2 :(得分:0)

嗨Deki Kurnia Hadi Permana,

有很多方法可以将数据从一个类传输到另一个类,但是对于活动,不需要做任何事情,它们提供了使用“Intent”数据将数据传输到另一个活动的功能,

以下是您可以在其他活动中发送和访问数据的代码。

FirstActivity.class

Intent callIntent=new Intent(FirstActivity.this,SecondActivity.class);
        callIntent.putExtra("urlToLaunch","post url here");
        startActivity(callIntent);

SecondActivity.class
Bundle bundle=getIntent().getExtras();
        if(bundle!=null){
            String urlToLaunch=bundle.getString("urlToLaunch");
//            set In webbrowser
        }