Android获取网页信息,天气
发布时间
阅读量:
阅读量
背景:通过天气接口获取天气具体内容并显示在Android手机上
在后面加上所要查询的城市就可以了(国内)
先上效果图:
这是网页显示的,我们的目的就是要先拿到这个全部内容

手机截图

日志(太长了,后面截不到)

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edit_city"
android:layout_width="182dp"
android:layout_height="wrap_content"
android:hint="please input your city"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.45"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.03" />
<Button
android:id="@+id/getdata"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:onClick="send"
android:text="query"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#ffff"
android:background="#669999 "
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.457"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.138" />
<TextView
android:id="@+id/data_show"
android:layout_width="305dp"
android:layout_height="400dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.796" />
</android.support.constraint.ConstraintLayout>
数据展示:
case R.id.getdata:
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
try {
String city=edit_city.getText().toString().trim();
Log.d("001",city);
String path="http://wthrcdn.etouch.cn/weather_mini?city="+city;
Log.d("002",path);
//html = HtmlService.getHtml("http://wthrcdn.etouch.cn/weather_mini?city=%E9%93%B6%E5%B7%9D");
html = HtmlService.getHtml(path);
Log.d("003",html);
} catch (Exception e) {
e.printStackTrace();
}
webDataShow.post(new Runnable() {
@Override
public void run() {
webDataShow.setText(html);
}
});
}
});
thread.start();
全部评论 (0)
还没有任何评论哟~
