ºÇ½ª¹¹¿·¡§
t_yokky2002 2011ǯ10·î16Æü(Æü) 22:32:09ÍúÎò
Android¥×¥í¥¸¥§¥¯¥È¤òºîÀ®¤·¡¢¥ê¥¹¥È¥Ó¥å¡¼¤ò»È¤Ã¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤òºîÀ®¤·¤Æ¤¯¤À¤µ¤¤¡£
¹àÌÜ | ÀßÄêÆâÍÆ |
---|---|
¥×¥í¥¸¥§¥¯¥È̾ | practice_listview_pref |
¥Ó¥ë¥É¥¿¡¼¥²¥Ã¥È | Android 2.2 |
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó̾ | listview_pref |
¥Ñ¥Ã¥±¡¼¥¸Ì¾ | jp.co.example.listview |
¥¢¥¯¥Æ¥£¥Ó¥Æ¥£Ì¾ | ListviewPrefActivity |
ºÇ¾®SDK¥Ð¡¼¥¸¥ç¥ó | 8 |
¥ï¡¼¥¥ó¥°¥»¥Ã¥È | ¥ï¡¼¥¥ó¥°¥»¥Ã¥È¤Ë¥×¥í¥¸¥§¥¯¥È¤òÄɲä˥Á¥§¥Ã¥¯ |
![](https://image02.seesaawiki.jp/a/r/androider/b99873f8d6e77830.png)
¥ì¥¤¥¢¥¦¥È¤ò¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="wrap_content" ¡¡¡¡¡¡¡¡ android:background="#FF909090"> <!-- ¥ê¥¹¥È¥Ó¥å¡¼ --> <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <!-- ¥ê¥¹¥È¤¬¶õ¤Î¤È¤¤Ëɽ¼¨ --> <TextView android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
¥¢¥¯¥Æ¥£¥Ó¥Æ¥£¤ò¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
public class ListviewPrefActivity extends ListActivity { /** Called when the activity is first created. */ private ArrayAdapter<String> mAdapter; private static final String[] VIEW_LIST_ITEMS = { "Ë̳¤Æ»", "ÀÄ¿¹¸©", "´ä¼ê¸©", "µÜ¾ë¸©", "½©Åĸ©", "»³·Á¸©", "Ê¡Å縩", "°ñ¾ë¸©", "ÆÊÌÚ¸©", "·²Çϸ©", "ºë¶Ì¸©", "ÀéÍÕ¸©", "ÅìµþÅÔ", "¿ÀÆàÀ", "¿·³ã¸©", "ÉÙ»³¸©", "ÀÐÀ", "Ê¡°æ¸©", "»³Íü¸©", "ĹÌ", "´ôÉ츩", "ÀŲ¬¸©", "°¦Ãθ©", "»°½Å¸©", "¼¢²ì¸©", "µþÅÔÉÜ", "ÂçºåÉÜ", "ʼ¸Ë¸©", "ÆàÎɸ©", "Ï²λ³¸©", "Ä»¼è¸©", "Å纬¸©", "²¬»³¸©", "¹Å縩", "»³¸ý¸©", "ÆÁÅ縩", "¹áÀ", "°¦É²¸©", "¹âÃθ©", "Ê¡²¬¸©", "º´²ì¸©", "Ĺºê¸©", "·§Ëܸ©", "Âçʬ¸©", "µÜºê¸©", "¼¯»ùÅ縩", "²Æ츩" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // ¥¢¥À¥×¥¿À¸À® mAdapter = new ArrayAdapter<String>( ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡getApplicationContext(), android.R.layout.simple_list_item_1, ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡VIEW_LIST_ITEMS); // ¥ê¥¹¥È¥Ó¥å¡¼¤Ë¥¢¥À¥×¥¿¤ò¥»¥Ã¥È setListAdapter(mAdapter); } @Override // ¥ê¥¹¥È¤Î¹Ô¤¬¥¯¥ê¥Ã¥¯¤µ¤ì¤¿»þ¤Î½èÍý protected void onListItemClick(ListView list, View view, int position, long id) { //¡¡¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¹àÌܤò¼èÆÀ¤·¡¢¥È¡¼¥¹¥È¤Ë¤Æɽ¼¨ String v = (String) list.getItemAtPosition(position); Toast.makeText(getApplicationContext(), v, Toast.LENGTH_SHORT).show(); } }
¼Â¹Ô¤¹¤ë¤È¡¢¥ê¥¹¥È¥Ó¥å¡¼¤Ë¤è¤Ã¤Æ¡¢ÅÔÆ»Éܸ©Ì¾¤Î¥ê¥¹¥È¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
¹àÌÜ | ÀßÄêÆâÍÆ |
---|---|
¥×¥í¥¸¥§¥¯¥È̾ | practice_listview_add |
¥Ó¥ë¥É¥¿¡¼¥²¥Ã¥È | Android 2.2 |
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó̾ | listview_add |
¥Ñ¥Ã¥±¡¼¥¸Ì¾ | jp.co.example.listview |
¥¢¥¯¥Æ¥£¥Ó¥Æ¥£Ì¾ | ListviewAddActivity |
ºÇ¾®SDK¥Ð¡¼¥¸¥ç¥ó | 8 |
¥ï¡¼¥¥ó¥°¥»¥Ã¥È | ¥ï¡¼¥¥ó¥°¥»¥Ã¥È¤Ë¥×¥í¥¸¥§¥¯¥È¤òÄɲä˥Á¥§¥Ã¥¯ |
![](https://image01.seesaawiki.jp/a/r/androider/110d59b5da28e81c.png)
¥ì¥¤¥¢¥¦¥È(res/layout/main.xml)¤ò¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent"> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="55dip" android:stackFromBottom="true" android:transcriptMode="alwaysScroll" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" android:layout_gravity="bottom"> <EditText android:id="@+id/edit_text" android:layout_height="wrap_content" android:layout_width="match_parent" android:singleLine="true" android:textSize="15sp" android:layout_weight="1" android:hint="ÆþÎϤ·¤Æ¤¯¤À¤µ¤¤"/> <Button android:id="@+id/add_button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/add_button_label" /> </LinearLayout> </FrameLayout>
¥ì¥¤¥¢¥¦¥È(res/layout/list_row.xml)¤ò¿·µ¬ºîÀ®¤·¡¢¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
<?xml version="1.0" encoding="UTF-8" ?> <!-- list_row.xml --> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_row_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="10dip" android:paddingBottom="10dip" android:textSize="15sp" android:textColor="@android:color/black" android:background="#7294c1" android:text="@string/empty_message" />
res/values/strings.xml¤Ë¡¢¼¡¤ÎÆâÍƤòÄɲ䷤Ƥ¯¤À¤µ¤¤¡£
<resources> <!-- ¢¤³¤³¤«¤é¡¡--> <string name="empty_message">¥ê¥¹¥È¤¬¶õ¤Ç¤¹</string> <string name="add_button_label">ÄɲÃ</string> <!-- ¢¬¤³¤³¤Þ¤Ç --> </resources>
¥¢¥¯¥Æ¥£¥Ó¥Æ¥£¤ò¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
public class ListviewAddActivity extends ListActivity { ArrayAdapter<String> mAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_row, new ArrayList<String>()); setListAdapter(mAdapter); Button button = (Button) findViewById(R.id.add_button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); addStringData(); } }); } private void addStringData() { EditText edit = (EditText) findViewById(R.id.edit_text); mAdapter.add(edit.getText().toString()); edit.setText(""); } }
¼Â¹Ô¤·¤Æ¤¯¤À¤µ¤¤¡£¥Æ¥¥¹¥È¥Ü¥Ã¥¯¥¹¤ËÆþÎϤ·¤¿ÆâÍƤ¬¡¢Äɲåܥ¿¥ó²¡²¼»þ¤Ë¥ê¥¹¥È¤ËÈ¿±Ç¤µ¤ì¤Þ¤·¤¿¤«¡£
°Ê¾å¤Ç¡¢ËÜÆü¤Î±é½¬¤Ï½ªÎ»¤Ç¤¹¡£¤ª¤Ä¤«¤ì¤µ¤Þ¤Ç¤·¤¿¡£
¤³¤Î¥Ú¡¼¥¸¤Ø¤Î¥³¥á¥ó¥È
n3bsso <a href="http://yttjpiulrgcw.com/">yttjpiulrgcw</a>, [url=http://vfjgloqasdzt.com/]vfjgloqasdzt[/url], [link=http://ggwsiynjahqp.com/]ggwsiynjahqp[/link], http://nqintxmozxnu.com/