今天講解的知識(shí)點(diǎn)是Arrayadapter這個(gè)類,這個(gè)是一個(gè)適配器,它實(shí)現(xiàn)的是Adapter接口,和它類似的有simpleadapter和baseadapter,其中simpleadapter這個(gè)類,大家千萬(wàn)不要為它的名字忽悠了,其實(shí)這個(gè)類的功能非常強(qiáng)大,我先結(jié)合api把a(bǔ)rrayadapter講好,大家學(xué)習(xí)另外類的時(shí)候就很簡(jiǎn)單了,接下來(lái),接下來(lái)就進(jìn)入課程的講解
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、網(wǎng)站空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、遂寧網(wǎng)站維護(hù)、網(wǎng)站推廣。
完成如下功能:
視頻播放地址:http://v.youku.com/v_show/id_XNzMzNTc2ODg0.html
如果有疑問(wèn),請(qǐng)發(fā)送到我的郵箱:[email protected]
用戶輸入,點(diǎn)擊確定,再次輸入,任一次數(shù),點(diǎn)擊顯示,在按鈕地下,顯示輸入的數(shù)據(jù);
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("請(qǐng)?jiān)俅屋斎?); } }); 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="一個(gè)簡(jiǎn)單的arrayadapter的例子" /> <EditText android:id="@+id/ed_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="請(qǐng)輸入您想輸入的內(nèi)容" /> <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>
網(wǎng)頁(yè)名稱:androidarrayadapter適配器
本文鏈接:http://www.2m8n56k.cn/article26/pjedcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、外貿(mào)建站、網(wǎng)站改版、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)