今天讲解的知识点是Arrayadapter这个类,这个是一个适配器,它实现的是Adapter接口,和它类似的有simpleadapter和baseadapter,其中simpleadapter这个类,大家千万不要为它的名字忽悠了,其实这个类的功能非常强大,我先结合api把arrayadapter讲好,大家学习另外类的时候就很简单了,接下来,接下来就进入课程的讲解
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、网站空间、营销软件、网站建设、遂宁网站维护、网站推广。
完成如下功能:
视频播放地址:http://v.youku.com/v_show/id_XNzMzNTc2ODg0.html
如果有疑问,请发送到我的邮箱:whsgzcy@foxmail.com
用户输入,点击确定,再次输入,任一次数,点击显示,在按钮地下,显示输入的数据;
package com.example.text111; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; public class MainActivity extends Activity { private ListView list; private Button btn_write, btn_show; private EditText ed_content; private ArrayAdapter<String> adpter1; private List<String> ll; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list = (ListView)findViewById(R.id.list); ed_content = (EditText)findViewById(R.id.ed_content); btn_write = (Button)findViewById(R.id.btn_write); btn_show = (Button)findViewById(R.id.btn_show); ll = new ArrayList<String>(); btn_write.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { ll.add(ed_content.getText().toString()); ed_content.setText(""); ed_content.setHint("请再次输入"); } }); adpter1 = new ArrayAdapter<String> (this, R.layout.show, R.id.content, ll); btn_show.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { list.setAdapter(adpter1); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } mainactivity.xml: [html] view plaincopy <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="一个简单的arrayadapter的例子" /> <EditText android:id="@+id/ed_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入您想输入的内容" /> <Button android:id="@+id/btn_write" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="确定" /> <Button android:id="@+id/btn_show" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="显示" /> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" ></ListView> </LinearLayout> show.xml代码如下 [html] view plaincopy <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/content" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
网页名称:androidarrayadapter适配器
本文链接:https://www.cdcxhl.com/article26/pjedcg.html
成都网站建设公司_创新互联,为您提供营销型网站建设、外贸建站、网站改版、移动网站建设、网站导航、网站排名
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联