android欢迎界面并执行任务
16lz
2021-01-23
<?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>
更多相关文章
- Android APP--建立简单的交互界面
- Android中编码实现软件界面
- android checkbox 定制(修改checkbox 的图片)
- 【Android】简单图片浏览器
- android图像处理系列之三--图片色调饱和度、色相、亮度处理
- Android使用xml自定义图片
- android原生音乐播放器界面字体显示不全
- Android 图片缩放与旋转
- android 获取图片