One of the mad Brush Android examples: Readasset

Source: Internet
Author: User

One of the mad Brush Android examples: Readasset description

The Mad Brush Android sample series has opened. Each learning an Android paradigm, a single example generates a running app and a brief analysis of key source code. Then provide the packaged source code download.

Function

The function is simple to read the resources that the app comes with, such as a text.
The code package is here, without the download points:
http://download.csdn.net/detail/logicteamleader/8780131

Source

The Readasset example comes from the com.example.android.apis.content.ReadAsset of Android-20.

Environment

Code Runtime Environment:
1.adt2014 version;
2.android:minsdkversion= "8"; android:targetsdkversion= "20"
The APPCOMPATV7 has been generated in 3.workspace, and its version is android-22;

Code
/* Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "Licen Se "); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by appli Cable law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, * without Warranties or CONDITIONS of any KIND, either express OR implied. * See the License for the specific language governing permissions and * limitations under the License. */ PackageCom.dumaisoft.readasset;ImportJava.io.IOException;ImportJava.io.InputStream;Importandroid.app.Activity;ImportAndroid.content.res.AssetManager;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView;/** * Demonstration of styled text resources. * * Public  class readasset extends Activity{    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);//See Assets/res/any/layout/styled_text.xml for this        //view layout definition.Setcontentview (R.layout.read_asset);//programmatically load text from a asset and place it into the        //Text view. Note that the text we were loading is ASCII, so we        //need to convert it to UTF-16.        Try{Assetmanager Assetmanager = This. Getassets (); InputStream is = Assetmanager.open ("Read_asset.txt");//We guarantee The Available method returns the total            //size of the asset of course, this does mean .            //Asset can ' t be more than 2 gigs.            intSize = Is.available ();//Read the entire asset into a local byte buffer.            byte[] buffer =New byte[Size];            Is.read (buffer); Is.close ();//Convert the buffer into a string.String Text =NewString (buffer);//Finally stick the string into the text view.TextView TV = (TextView) Findviewbyid (R.id.text);        Tv.settext (text); }Catch(IOException e) {//should never happen!            Throw NewRuntimeException (e); }    }}

One of the mad Brush Android examples: Readasset

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.