zoukankan      html  css  js  c++  java
  • Android_2.2_eclips_ToDoList

    任务添加程序,输入信息点击方向键中介的键添加。KEYCODE_DPAD_CENTER

    (涉及内容,adapter简单应用,简单布局。)

    mainActivity

    package com.gongsi.todolist;

    import java.util.ArrayList;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.ArrayAdapter;
    import android.widget.EditText;
    import android.widget.ListView;
    /*
    * adapter增加list条目的demo
    */
    public class ToDoListActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListView myListView = (ListView)findViewById(R.id.myListView);
    final EditText myEditText = (EditText)findViewById(R.id.myEditText);

    final ArrayList<String> todoItems = new ArrayList<String>();
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1,
    todoItems);
    myListView.setAdapter(adapter);

    myEditText.setOnKeyListener(new View.OnKeyListener() {

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
    /*手机上下左右键的中间确定键 KEYCODE_DPAD_CENTER*/
    if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
    todoItems.add(0, myEditText.getText().toString());
    adapter.notifyDataSetChanged();//通知adapter更新
    myEditText.setText("");
    return true;
    }
    }
    return false;
    }
    });
    }
    }


    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:layout_width="fill_parent"
    android:layout_height
    ="wrap_content"
    android:id
    ="@+id/myEditText"
    android:text
    ="New To Do List"
    />
    <ListView
    android:id="@+id/myListView"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent"
    />
    </LinearLayout>
  • 相关阅读:
    Redis-安装
    Redis-介绍
    Redis 教程(转)
    C# Redis 帮助类
    sublime text3---Emmet:HTML/CSS代码快速编写神器
    Sublime Text3 Package Control和Emmet插件安装方法
    vs2010音频文件压缩 调用lame_enc.dll将WAV格式转换成MP3
    vs学习过程中遇见的各种问题
    vs2010中添加dll文件
    解决angular11打包报错Type 'Event' is missing the following properties from type 'any[]': ...Type 'Event' is not assignable to type 'string'
  • 原文地址:https://www.cnblogs.com/flyingsir/p/2263735.html
Copyright © 2011-2022 走看看