<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <ImageView        android:id="@+id/imageView1"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:scaleType="centerCrop"        android:src="@drawable/s1" />    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="TextView" /></LinearLayout>
package com.example.start_1;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import android.os.Bundle;import android.os.Handler;import android.util.Log;import android.widget.ImageView;import android.widget.TextView;import android.app.Activity;import android.content.ContentValues;import android.content.Intent;import android.database.sqlite.SQLiteDatabase;public class WelcomeA extends Activity {private String result_weather = ""; // 声明一个代表显示内容的字符串private TextView textView1;    private ImageView  imageView1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);textView1 = (TextView) findViewById(R.id.textView1);imageView1=(ImageView)findViewById(R.id.imageView1);new Handler().postDelayed(new Runnable() {@Overridepublic void run() {new Thread(new Runnable() {public void run() {String target = "";try {target = "http://op.juhe.cn/onebox/weather/query?cityname="+ java.net.URLEncoder.encode("合肥", "utf-8")+ "&dtype=json&key=55fae8......";/////需要自己申请} catch (UnsupportedEncodingException e1) {// TODO 自动生成的 catch 块e1.printStackTrace();}URL url;try {url = new URL(target);HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); // 创建一个HTTP连接InputStreamReader in = new InputStreamReader(urlConn.getInputStream()); // 获得读取的内容// ,从字节流转换为字符流BufferedReader buffer = new BufferedReader(in); // 获取输入流对象// ,从字符输入流中读取文本String inputLine = null;// 通过循环逐行读取输入流中的内容while ((inputLine = buffer.readLine()) != null) {result_weather += inputLine + "\n";}in.close(); // 关闭字符输入流对象urlConn.disconnect(); // 断开连接Log.i("result_weather", result_weather);} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}CityDBHelper dbHelper = new CityDBHelper(WelcomeA.this,"city_db", null, 1);SQLiteDatabase db = dbHelper.getWritableDatabase();ContentValues cv = new ContentValues();cv.put("city", result_weather);db.insert("city_table", null, cv);db.close();Log.i("插入成功", "插入成功");// resultTextView.setText("");}// /run()}).start();// textView1.setText(text);Intent intent = new Intent(WelcomeA.this, MainActivity.class);startActivity(intent);WelcomeA.this.finish();}}, 4000);}// /onCreate}// WelcomeA

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="${relativePackage}.${activityClass}" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>
package com.example.start_1;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.start_1"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="15"        android:targetSdkVersion="16" />    <uses-permission android:name="android.permission.INTERNET" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name=".MainActivity"            android:label="@string/app_name" >            <intent-filter>                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity            android:name=".WelcomeA"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>
  






更多相关文章

  1. android 复制、粘贴文字
  2. Android(安卓)读写文件的N种写法
  3. [原]android 中如何飞行模式的几个操作
  4. Android定制出厂默认输入法
  5. android 自定义输入框
  6. Android的文本编解码工具类
  7. android 读取,写入图片到sd卡源码
  8. android HttpURLConnection 连接网络 读取返回数据
  9. input 之我见1

随机推荐

  1. Android应用程序消息处理机制(Looper、Han
  2. android 模拟器使用指导
  3. 2011.09.26——— android sample之Notep
  4. 设置listview中的item的颜色
  5. android camera
  6. android 进制转换 (高低位)
  7. 如何进行Android单元测试
  8. Android全屏设置的两种方式
  9. Android(安卓)使用 HTTPS SSLProtocolExc
  10. 【Android(安卓)M】Monkey命令源码及是否