




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、實驗5.1:package com.example.test5;import android.os.Bundle;import android.R.string;import android.app.Activity;import android.view.Menu;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ArrayAdapter;import android.wid
2、get.ListView;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity private static final String strs = new String "first", "second", "third", "fourth", "fifth"/定義一個String數(shù)組用來顯示ListView的內(nèi)容Overrideprotecte
3、d void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ListView list = (ListView)findViewById(R.id.listView1);list.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strs);list.setOnItemClickListener(new On
4、ItemClickListener()Overridepublic void onItemClick(AdapterView<?> arg0, View view, int arg2, long id) / TODO Auto-generated method stubString str = (String) (TextView) view).getText();/Toast.makeText(this, text, duration)Toast.makeText(getApplicationContext(),str, Toast.LENGTH_SHORT).show(););
5、Overridepublic 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;Layout XML:<RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" an
6、droid:layout_height="match_parent" android:paddingBottom="dimen/activity_vertical_margin" android:paddingLeft="dimen/activity_horizontal_margin" android:paddingRight="dimen/activity_horizontal_margin" android:paddingTop="dimen/activity_vertical_margin&quo
7、t; tools:context=".MainActivity" > <TextView android:id="+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="string/hello_world" /> <ListView android:id="+id/listView1" android:l
8、ayout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="+id/textView1" android:layout_below="+id/textView1" android:layout_marginLeft="26dp" android:layout_marginTop="22dp" > </ListView></Relati
9、veLayout>實驗5.2:package org.example.test;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.ListActivity;import android.os.Bundle;import android.widget.SimpleAdapter;public class test5 extends ListActivity /* Called when the activity i
10、s first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); /setContentView(R.layout.main); SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.item, new String"title","info","img",new intR.id.title,R.
11、,R.id.img); setListAdapter(adapter); private List<Map<String,Object>>getData() List<Map<String,Object>>list = new ArrayList<Map<String,Object>>(); Map<String,Object> map = new HashMap<String,Object>(); map.put("title", "G1");
12、 map.put("info", "google 1"); map.put("img", R.drawable.aomen); list.add(map); map = new HashMap<String,Object>(); map.put("title", "G2"); map.put("info", "google 2"); map.put("img", R.drawable.photo1426); list.add
13、(map); map = new HashMap<String,Object>(); map.put("title", "G3"); map.put("info", "google 3"); map.put("img", R.drawable.photo1450); list.add(map); return list; Layout XmlItem.XML:<?xml version="1.0" encoding="UTF-8"?>
14、;<LinearLayout xmlns:android=" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" ><ImageViewandroid:id="+id/img" android:layout_width="wrap_content" android:layout_height="wrap_
15、content" android:layout_margin="5px"/> <LinerLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="+id/title" android:layout_width="wrap_content&qu
16、ot; android:layout_height="wrap_content" android:textSize="22px"/> <TextView android:id="+id/info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="13px"/> </LinerLayout></LinearLa
17、yout>Main.xml:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><ListView android:id="+id/ListView01&
18、quot; android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView></LinearLayout>實驗5.3:package com.example.test5_new3;import android.os.Bundle;import java.util.ArrayList;import java.util.HashMap;import android.app.Activity;import android.con
19、tent.Context;import android.view.Menu;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.BaseAdapter;import android.widget.GridView;import android.widget.ImageView;import android.widget.
20、SimpleAdapter;public class MainActivity extends Activity private GridView gridview;private Integer mThumbIds=R.drawable.photo1423,R.drawable.photo1424,R.drawable.photo1426,R.drawable.photo1433,R.drawable.photo1441,R.drawable.photo1450,R.drawable.photo1453,R.drawable.photo1796,R.drawable.photo1803,;O
21、verrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);gridview =(GridView)findViewById(R.id.gridView1);/gridview.setAdapter(new ImageAdapter(this);ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList
22、<HashMap<String, Object>>();/初始化列表數(shù)據(jù) for (int i = 0; i < 9; i+) HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", mThumbIdsi);/ 添加圖像資源的ID ID和hashMap數(shù)組進行綁定 map.put("ItemText", "宮式布局" + String.valueOf(i);/ 按序號做Ite
23、mText lstImageItem.add(map); SimpleAdapter saImageItems = new SimpleAdapter(this, / 沒什么解釋 lstImageItem,/ 數(shù)據(jù)來源 R.layout.item,/ night_item的XML實現(xiàn) / 動態(tài)數(shù)組與XML:Item對應(yīng)的子項 new String "ItemImage", "ItemText" , / Item的XML文件里面的一個ImageView01,兩個TextView ID new int R.id.ItemImage01, R.id.ItemT
24、ext01 ); / 添加并且顯示 gridview.setAdapter(saImageItems); / 添加消息處理 gridview.setOnItemClickListener(new ItemClickListener(); class ItemClickListener implements OnItemClickListener public void onItemClick(AdapterView<?> arg0,/ The AdapterView where the click happened View arg1,/ The view within the A
25、dapterView that was clicked int position,/第幾項的意思 The position of the view in the adapter long Item_id/ The row id of the item that was clicked ) / 在本例中arg2=arg3 SuppressWarnings("unchecked") HashMap<String, Object> item = (HashMap<String, Object>) arg0.getItemAtPosition(positio
26、n); / 顯示所選Item的ItemText setTitle(String) item.get("ItemText"); Overridepublic 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;Activity.xml:<RelativeLayout xmlns:android
27、=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="dimen/activity_vertical_margin" android:paddingLeft="dimen/activity_horizontal_margin" android:paddingRight="dimen/activity_horizont
28、al_margin" android:paddingTop="dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="+id/but
29、ton1" android:layout_below="+id/button1" android:layout_marginTop="21dp" android:text="Button" /> <Button android:id="+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft=
30、"+id/button2" android:layout_below="+id/button2" android:layout_marginTop="29dp" android:text="Button" /> <Button android:id="+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layo
31、ut_alignLeft="+id/button3" android:layout_below="+id/button3" android:layout_marginTop="20dp" android:text="Button" /> <Button android:id="+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"
32、 android:layout_alignLeft="+id/button4" android:layout_below="+id/button4" android:layout_marginTop="30dp" android:text="Button" /> <Button android:id="+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_
33、content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="44dp" android:text="Button" /></RelativeLayout>Main.xml:<?xml version="1.0" encoding="UTF-8"?><LinearLayou
34、t xmlns:android=" xmlns:tools=" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="+id/username_view" android:layout_height="wrap_content" android:layout_width
35、="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:text="請輸入用戶名:" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="+id/username_edit" android:layout_height=
36、"wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:capitalize="none" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="
37、;+id/password_view" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:text="請輸入密碼:" android:textAppearance="?android:attr/textAppearanceMedi
38、um" /> <EditText android:id="+id/password_edit" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:capitalize="none" android:passwo
39、rd="true" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout>實驗5.4<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android=" xmlns:tools=" android:layout_width="fill_parent" android:layo
40、ut_height="wrap_content" android:orientation="vertical"> <TextView android:id="+id/username_view" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight=&q
41、uot;20dip" android:text="請輸入用戶名:" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="+id/username_edit" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft=&qu
42、ot;20dip" android:layout_marginRight="20dip" android:capitalize="none" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="+id/password_view" android:layout_height="wrap_content" android:layout_width="
43、wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:text="請輸入密碼:" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="+id/password_edit" android:layout_height="wr
44、ap_content" android:layout_width="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:capitalize="none" android:password="true" android:textAppearance="?android:attr/textAppearanceMedium" /><
45、/LinearLayout><RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="dimen/activity_vertical_margin" android:paddingLeft="dimen/activity_horizontal_margin" a
46、ndroid:paddingRight="dimen/activity_horizontal_margin" android:paddingTop="dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_con
47、tent" android:layout_alignLeft="+id/button1" android:layout_below="+id/button1" android:layout_marginTop="21dp" android:text="Button" /> <Button android:id="+id/button3" android:layout_width="wrap_content" android:layout_height=&
48、quot;wrap_content" android:layout_alignLeft="+id/button2" android:layout_below="+id/button2" android:layout_marginTop="29dp" android:text="Button" /> <Button android:id="+id/button4" android:layout_width="wrap_content" android:la
49、yout_height="wrap_content" android:layout_alignLeft="+id/button3" android:layout_below="+id/button3" android:layout_marginTop="20dp" android:text="Button" /> <Button android:id="+id/button5" android:layout_width="wrap_content&quo
50、t; android:layout_height="wrap_content" android:layout_alignLeft="+id/button4" android:layout_below="+id/button4" android:layout_marginTop="30dp" android:text="Button" /> <Button android:id="+id/button1" android:layout_width="wra
51、p_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="44dp" android:text="Button" /></RelativeLayout>package com.example.test5_new4;import a
52、ndroid.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.content.DialogInterface.OnMultiChoiceClickListener;import android.view.LayoutInflater;import android.view.Menu;impo
53、rt android.view.View;import android.widget.Button;import android.widget.Toast;public class MainActivity extends Activity Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button bth1 = (Button)findViewById(R.id.button
54、1);bth1.setOnClickListener(new View.OnClickListener() Overridepublic void onClick(View arg0) / TODO Auto-generated method stubnew AlertDialog.Builder(MainActivity.this) .setTitle("標(biāo)題") .setMessage("文本對話框") .setPositiveButton("確定", null) .setNegativeButton("取消"
55、, null) .show(););Button bth2 = (Button)findViewById(R.id.button2);bth2.setOnClickListener(new View.OnClickListener() String items="亞洲","南極洲","北美洲","南美洲","歐洲","非洲","大洋洲"Overridepublic void onClick(View arg0) / TODO Auto-generated
56、method stubnew AlertDialog.Builder(MainActivity.this) .setTitle("七大洲列表") .setItems(items, null) .show(););Button bth3 = (Button)findViewById(R.id.button3);bth3.setOnClickListener(new View.OnClickListener() String items="亞洲","南極洲","北美洲","南美洲","歐洲","非洲","大洋洲"String itemsname;Overridepublic void onClick(View arg0) / TODO Auto-generated method stubnew AlertDialog.Builder(MainActivity.this) .setIcon(R.drawable.globe) .setTitle(&q
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 內(nèi)購房轉(zhuǎn)讓合同范本
- 個人轉(zhuǎn)讓德文合同范本
- 分包混凝土合同范本
- 買賣車位轉(zhuǎn)讓合同范本
- 包子工用工合同范本
- 創(chuàng)業(yè)加盟合同范本
- 廣西買房合同范本
- 出國勞務(wù)外派合同范本
- 勞動合同范本工資
- 出租包車合同范本
- 2022-2023學(xué)年湖南省長沙市統(tǒng)招專升本語文模擬練習(xí)題三及答案
- 社會救助法課件
- 1.裝配式建筑概述(裝配式混凝土結(jié)構(gòu)施工技術(shù))
- 第七講+漢字字音
- 新零件的成熟保障MLA
- 【基于杜邦分析法的企業(yè)盈利能力研究國內(nèi)外文獻綜述4000字】
- 初中語文七下-上下句默寫
- 《董存瑞舍身炸碉堡》PPT課件新
- 新川教版信息技術(shù)六年級下冊全冊教案
- 第20章補充芯片粘接技術(shù)
- 旅行社運營實務(wù)電子課件 5.1 旅行社電子商務(wù)概念
評論
0/150
提交評論