package training.android.com; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; public class fileWriteRead extends Activity implements OnClickListener { /** Called when the activity is first created. */ private EditText edit_Text;// 编缉文本框 private Button btn_Save;// 保相聚按钮 private String text_of_input;// 输入文本值 private OutputStream os;// 输出流 private TextView showMyText;// 显示文本 private Button btnOpenText, btnCleanText;// 打开与清空按钮事件 private Button btnOpenRaw; private String Text_of_output;// 输入出文本 private InputStream is;// 输入流 private InputStream iputRaw;//静态文件流 private byte[] b; private ScrollView scroll; private int ori=0; /** * 页面的初始化 * */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); showLayout("main"); UIinit("main"); Logic("main"); } /** * 通过页面名称去显示各页面信息 创建人:周昕 创建时间:2010-4-8 方法名称:showLayout * * @param layoutName */ private void showLayout(String layoutName) { if (layoutName.equals("main")) { setContentView(R.layout.main); } if (layoutName.equals("openfile")) { setContentView(R.layout.openfile); } } /** * 通过页面名称去初始化控件 * * @param uiName * 创建人:周昕 &&&&&&&& 创建时间:2010-4-8 */ private void UIinit(String uiName) { if (uiName.equals("main")) { edit_Text = (EditText) findViewById(R.id.Edit_text); btn_Save = (Button) findViewById(R.id.Button_save); } if (uiName.equals("openfile")) { btnOpenText = (Button) findViewById(R.id.Button_openTxt); btnCleanText = (Button) findViewById(R.id.Button_clean); btnOpenRaw = (Button) findViewById(R.id.Button_openRaw); showMyText = (TextView) findViewById(R.id.TextView_showTxt); } } /** * 通过页面名称去对各Button指定事件 * * @param pageName * 创建人:周昕******** 创建时间:2010-4-8 */ private void Logic(String pageName) { if (pageName.equals("main")) { btn_Save.setOnClickListener(this); } if (pageName.equals("openfile")) { btnOpenText.setOnClickListener(this); btnCleanText.setOnClickListener(this); btnOpenRaw.setOnClickListener(this); } } /** * 在Toast中显示指定的字段 * * @param strTitle */ private void NoteDebug(String strTitle) { Toast.makeText(this, strTitle, Toast.LENGTH_SHORT).show(); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.Button_save: NoteDebug("文件保存"); text_of_input = edit_Text.getText().toString(); try { os = this.openFileOutput("txtME", MODE_PRIVATE); os.write(text_of_input.getBytes()); } catch (FileNotFoundException e) { NoteDebug("文件关闭失败" + e); } catch (IOException e) { NoteDebug("文件写入失败" + e); } finally { try { os.close(); } catch (IOException e) { NoteDebug("关闭文件失败" + e); } } edit_Text.setText(""); break; case R.id.Button_openTxt: NoteDebug("打开文件"); try { is = this.openFileInput("txtME"); b = new byte[1024]; int length = is.read(b); Text_of_output = new String(b); setTitle("文件字数" + length); showMyText.setText(Text_of_output); } catch (FileNotFoundException e) { NoteDebug("文件打开失败" + e); } catch (IOException e) { // TODO Auto-generated catch block NoteDebug("文件读取失败" + e); } finally { try { is.close(); } catch (IOException e) { NoteDebug("文件关闭失败" + e); } } break; case R.id.Button_openRaw: NoteDebug("打开静态文件"); try { iputRaw = this.getResources().openRawResource(R.raw.filetext); b = new byte[102400]; int length = iputRaw.read(b); Text_of_output=""; Text_of_output = new String(b); setTitle("静态文件字数" + length); showMyText.setText(Text_of_output); showMyText.setHorizontallyScrolling(true); scroll = (ScrollView)findViewById(R.id.scroll); scroll.smoothScrollBy(ori, 0); } catch (FileNotFoundException e) { NoteDebug("静态文件打开失败" + e); } catch (IOException e) { // TODO Auto-generated catch block NoteDebug("静态文件读取失败" + e); } finally { try { iputRaw.close(); } catch (IOException e) { NoteDebug("静态文件关闭失败" + e); } } break; case R.id.Button_clean: NoteDebug("清空文件"); showMyText.setText(""); NoteDebug("清空"); break; } } public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, 1, 1, "edit"); menu.add(0, 2, 2, "open"); menu.add(0, 3, 3, "clear"); return super.onCreateOptionsMenu(menu); } public boolean onOptionsItemSelected(MenuItem items) { switch (items.getItemId()) { case 1: showLayout("main"); UIinit("main"); Logic("main"); NoteDebug("编缉文件"); break; case 2: showLayout("openfile"); UIinit("openfile"); Logic("openfile"); NoteDebug("打开件"); break; case 3: showLayout("openfile"); UIinit("openfile"); Logic("openfile"); NoteDebug("清空文件"); break; } return super.onOptionsItemSelected(items); } private Handler message = new Handler(){ public void handleMessage(Message msg) { doScrow(); } }; public class TimerLoop implements Runnable { @Override public void run() { // TODO Auto-generated method stub while(true){ loop(500); message.sendEmptyMessage(0); } } } //因为sleep()似乎不好用 所以采用这种方法计时 public void loop(long i){ long j = i; while(j>0){ j = j-1; } } public boolean onKeyDown(int keyCode, KeyEvent msg){ // Thread loop = new Thread(new TimerLoop()); // loop.start(); return super.onKeyDown(keyCode, msg); } public void doScrow(){ int now = scroll.getScrollY(); if(ori == now){ scroll.scrollTo(now, 0); ori = -1; } else { scroll.smoothScrollBy(10, 10); ori = now; } } }
main.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:id="@+id/Edit_text" android:layout_width="fill_parent" android:layout_height="350px"> </EditText> <Button android:text="保存" android:id="@+id/Button_save" android:layout_width="80px" android:layout_height="wrap_content"> </Button> </LinearLayout>
open.xml
<?xml version="1.0" encoding="UTF-8"?> <AbsoluteLayout android:id="@+id/openlayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <!-- <ScrollView android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:fadingEdge="vertical" android:id="@+id/scroll"> --> <ScrollView android:id="@+id/scroll" android:layout_width="fill_parent" android:layout_height="300dip" > <LinearLayout android:layout_width="fill_parent" android:layout_height="380px"> <TextView android:id="@+id/TextView_showTxt" android:layout_width="314px" android:layout_height="373px" android:scrollbars="vertical" android:fadingEdge="vertical" android:autoText="true" android:layout_x="3px" android:layout_y="3px" > <!-- android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" --> </TextView> </LinearLayout> </ScrollView> <Button android:id="@+id/Button_openTxt" android:layout_width="80px" android:layout_height="wrap_content" android:text="打开" android:layout_x="2px" android:layout_y="378px"> </Button> <Button android:id="@+id/Button_openRaw" android:layout_width="80px" android:layout_height="wrap_content" android:text="静态文件" android:layout_x="102px" android:layout_y="378px"> </Button> <Button android:id="@+id/Button_clean" android:layout_width="80px" android:layout_height="wrap_content" android:text="清空" android:layout_x="239px" android:layout_y="378px"> </Button> </AbsoluteLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="training.android.com" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".fileWriteRead" 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> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.MODE_WORLD_READABLE"></uses-permission> <uses-permission android:name="android.permission.MODE_WORLD_WRITEABLE"></uses-permission> </manifest>
您还没有登录,请您登录后再发表评论
综上所述,这个项目涵盖了Android开发中的一些基础但重要的概念和技术,如ListView的使用、数据结构设计、事件监听、滚动效果、编码处理以及兼容性问题。通过实践这个项目,开发者可以加深对Android UI设计和数据...
在Android平台上开发一款音乐播放器是一项复杂而有趣的任务,它涉及到多媒体处理、用户界面设计以及文件系统的操作。本文将深入探讨如何从SD卡获取音乐资源,实现歌词滚动功能,并给出一个名为“音乐播放器2”的项目...
阅读器应用可能会声明读取和写入存储的权限,因为文本文件的加载和保存需要这些权限。 4. **活动(Activity)**: Activity是Android应用中的主要组件,用于展示用户界面并处理用户交互。文本阅读器应用至少有一个主...
同时,Apache Commons IO库可以提供便利的文件操作功能,如读取、写入等,对于处理LRC文件非常有用。在Android环境中,我们可以借助Android SDK提供的`java.io`和`java.util`包进行文件读取和时间处理。 其次,为了...
UI设计方面,Android提供了多种布局和控件供开发者使用,如TextView用于显示文本,ImageView用于显示联系人头像,以及ImageButton和Button用于执行操作。同时,为了提供良好的用户体验,电话本可能还需要实现搜索...
5. **文件I/O操作**: 为了读取和加载电子书内容,开发者需要了解Android的文件系统和如何进行输入输出操作,包括读取和写入文件。 6. **文字渲染与排版**: 阅读器的核心功能是显示文本。这涉及到对字体、字号、行距...
这些API允许开发者读取、写入和操作Word文档的文本、样式、表格等元素。 2. **Android环境下的Word阅读**: 在Android系统上,由于其内存限制和对Java原生接口(JNI)的支持,直接使用Apache POI可能会遇到性能...
这些提供者公开了系统数据的访问接口,使得应用能够安全地读取和写入联系人、媒体文件和系统设置。 #### 11. **`android.telephony`** `android.telephony`类库专注于电话相关的功能,如拨打电话、接收来电和短信...
Toast用于短暂显示消息,而文件操作包括写入、读取文件,这对于存储用户数据或日志信息非常有用。 11. 安装和卸载程序 调用`PackageManager`提供的方法,如`installPackage()`和`uninstallPackage()`,可以实现程序...
例如,读取和写入联系人、媒体文件等。通过URI(统一资源标识符)来操作特定的数据集,ContentResolver提供了如查询、插入、更新和删除等操作。 3. **抽屉(Drawer)**:抽屉布局通常指的是Android中的滑动抽屉效果...
这就需要用到Java的IO流操作,如`FileOutputStream`和`FileInputStream`,用来写入和读取文件内容。 - **持久化数据**:为了在应用关闭后仍能保存备忘录,需要使用持久化的数据存储方式,例如SQLite数据库或...
5. **UI设计**:在Android应用中,聊天界面通常包含一个输入框用于输入消息,一个按钮用于发送,以及一个滚动列表用于显示聊天记录。使用Android的TextView、EditText和ListView等组件可以轻松实现。 6. **代码注释...
1、ANDROID文件系统与应用程序架构 7 1.1、ANDROID 文件系统 7 1.2、ANDROID应用程序架构 9 2、ANDROID应用程序结构 11 2.1、ACTIVITY 12 2.1.1、概述 12 2.1.2、Activity的生命周期 15 2.1.3、Activity 的创建 16 ...
9. **权限管理**:在Android 6.0及以上版本,需要在运行时请求读写存储权限,确保应用能够正常读取和写入文件。 10. **UI设计**:设计清晰易懂的UI界面,使用户能快速理解每个任务的状态。比如,可以通过不同的颜色...
因为涉及到本地数据存储和读取,应用可能需要请求写入外部存储的权限。在Android 6.0及以上版本,权限管理更加严格,需要在运行时动态请求权限。 9. **通知与提醒** 可能集成了通知功能,当用户到达或即将到达...
9. **权限管理**: 根据Android的权限模型,应用可能需要请求访问外部存储(读取/写入电子书)和互联网(下载更新或获取元数据)的权限。 10. **网络功能**: 如果阅读器支持在线阅读,它可能包含网络请求和数据解析...
在Android系统中,读取和写入外部存储(如SD卡)需要`READ_EXTERNAL_STORAGE`和`WRITE_EXTERNAL_STORAGE`权限: ```xml <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> ...
3. **文件系统访问**:Android提供`java.io.File`类来操作文件和目录,包括创建、删除、重命名、读取和写入文件。此外,Android 6.0及以上版本引入了运行时权限管理,访问外部存储(SD卡)需要用户在运行时授予相应...
在安卓应用程序开发中,了解和掌握关键概念是至关重要的。以下是一些基于题目内容的知识点详解: ...开发者需要理解组件的作用、布局管理、数据存储策略以及与用户交互的设计原则,才能构建出高质量的安卓应用。
3. **ListView与Adapter**:Android中的`ListView`是展示大量数据的理想选择,因为它可以进行滚动优化。在这个例子中,每个联系人信息会显示在一个ListView的Item上。适配器(Adapter)是连接数据源和ListView的关键...
相关推荐
综上所述,这个项目涵盖了Android开发中的一些基础但重要的概念和技术,如ListView的使用、数据结构设计、事件监听、滚动效果、编码处理以及兼容性问题。通过实践这个项目,开发者可以加深对Android UI设计和数据...
在Android平台上开发一款音乐播放器是一项复杂而有趣的任务,它涉及到多媒体处理、用户界面设计以及文件系统的操作。本文将深入探讨如何从SD卡获取音乐资源,实现歌词滚动功能,并给出一个名为“音乐播放器2”的项目...
阅读器应用可能会声明读取和写入存储的权限,因为文本文件的加载和保存需要这些权限。 4. **活动(Activity)**: Activity是Android应用中的主要组件,用于展示用户界面并处理用户交互。文本阅读器应用至少有一个主...
同时,Apache Commons IO库可以提供便利的文件操作功能,如读取、写入等,对于处理LRC文件非常有用。在Android环境中,我们可以借助Android SDK提供的`java.io`和`java.util`包进行文件读取和时间处理。 其次,为了...
UI设计方面,Android提供了多种布局和控件供开发者使用,如TextView用于显示文本,ImageView用于显示联系人头像,以及ImageButton和Button用于执行操作。同时,为了提供良好的用户体验,电话本可能还需要实现搜索...
5. **文件I/O操作**: 为了读取和加载电子书内容,开发者需要了解Android的文件系统和如何进行输入输出操作,包括读取和写入文件。 6. **文字渲染与排版**: 阅读器的核心功能是显示文本。这涉及到对字体、字号、行距...
这些API允许开发者读取、写入和操作Word文档的文本、样式、表格等元素。 2. **Android环境下的Word阅读**: 在Android系统上,由于其内存限制和对Java原生接口(JNI)的支持,直接使用Apache POI可能会遇到性能...
这些提供者公开了系统数据的访问接口,使得应用能够安全地读取和写入联系人、媒体文件和系统设置。 #### 11. **`android.telephony`** `android.telephony`类库专注于电话相关的功能,如拨打电话、接收来电和短信...
Toast用于短暂显示消息,而文件操作包括写入、读取文件,这对于存储用户数据或日志信息非常有用。 11. 安装和卸载程序 调用`PackageManager`提供的方法,如`installPackage()`和`uninstallPackage()`,可以实现程序...
例如,读取和写入联系人、媒体文件等。通过URI(统一资源标识符)来操作特定的数据集,ContentResolver提供了如查询、插入、更新和删除等操作。 3. **抽屉(Drawer)**:抽屉布局通常指的是Android中的滑动抽屉效果...
这就需要用到Java的IO流操作,如`FileOutputStream`和`FileInputStream`,用来写入和读取文件内容。 - **持久化数据**:为了在应用关闭后仍能保存备忘录,需要使用持久化的数据存储方式,例如SQLite数据库或...
5. **UI设计**:在Android应用中,聊天界面通常包含一个输入框用于输入消息,一个按钮用于发送,以及一个滚动列表用于显示聊天记录。使用Android的TextView、EditText和ListView等组件可以轻松实现。 6. **代码注释...
1、ANDROID文件系统与应用程序架构 7 1.1、ANDROID 文件系统 7 1.2、ANDROID应用程序架构 9 2、ANDROID应用程序结构 11 2.1、ACTIVITY 12 2.1.1、概述 12 2.1.2、Activity的生命周期 15 2.1.3、Activity 的创建 16 ...
9. **权限管理**:在Android 6.0及以上版本,需要在运行时请求读写存储权限,确保应用能够正常读取和写入文件。 10. **UI设计**:设计清晰易懂的UI界面,使用户能快速理解每个任务的状态。比如,可以通过不同的颜色...
因为涉及到本地数据存储和读取,应用可能需要请求写入外部存储的权限。在Android 6.0及以上版本,权限管理更加严格,需要在运行时动态请求权限。 9. **通知与提醒** 可能集成了通知功能,当用户到达或即将到达...
9. **权限管理**: 根据Android的权限模型,应用可能需要请求访问外部存储(读取/写入电子书)和互联网(下载更新或获取元数据)的权限。 10. **网络功能**: 如果阅读器支持在线阅读,它可能包含网络请求和数据解析...
在Android系统中,读取和写入外部存储(如SD卡)需要`READ_EXTERNAL_STORAGE`和`WRITE_EXTERNAL_STORAGE`权限: ```xml <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> ...
3. **文件系统访问**:Android提供`java.io.File`类来操作文件和目录,包括创建、删除、重命名、读取和写入文件。此外,Android 6.0及以上版本引入了运行时权限管理,访问外部存储(SD卡)需要用户在运行时授予相应...
在安卓应用程序开发中,了解和掌握关键概念是至关重要的。以下是一些基于题目内容的知识点详解: ...开发者需要理解组件的作用、布局管理、数据存储策略以及与用户交互的设计原则,才能构建出高质量的安卓应用。
3. **ListView与Adapter**:Android中的`ListView`是展示大量数据的理想选择,因为它可以进行滚动优化。在这个例子中,每个联系人信息会显示在一个ListView的Item上。适配器(Adapter)是连接数据源和ListView的关键...