国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

安卓開發中動態添加lsitV iew 代碼實例

2019-11-02 15:23:10
字體:
來源:轉載
供稿:網友

 這個很簡單 就是為了說明別忘了adapter.notifyDataSetChanged();

  喚醒一下,其實這個喚醒也就是在button下用 或者在別的控件下調用 如果是在getView下就不必了

  java代碼:

  public class DynamicListItems extends ListActivity {

  private static final String ITEM_KEY = "key";

  ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

  private SimpleAdapter adapter;

  private EditText newValue;

  @Override

  public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.dynamic_list);

  newValue = (EditText) findViewById(R.id.new_value_field);

  setListAdapter(new SimpleAdapter(this, list, R.layout.row, new String[] { ITEM_KEY }, new int[] { R.id.list_value }));

  ((ImageButton) findViewById(R.id.button)).setOnClickListener(getBtnClickListener());

  }

  private OnClickListener getBtnClickListener() {

  return new OnClickListener() {

  public void onClick(View view) {

  try {

  HashMap<String, String> item = new HashMap<String, String>();

  item.put(ITEM_KEY, newValue.getText().toString());

  list.add(item);

  adapter.notifyDataSetChanged();

  } catch (NullPointerException e) {

  Log.i("[Dynamic Items]", "Tried to add null value");

  }

  }

  };

  }

  }

  Java代碼:

  <?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"

  >

  <ListView android:id="@+id/android:list"

  android:layout_width="fill_parent"

  android:layout_height="0px"

  android:layout_weight="1"

  android:cacheColorHint="#00000000">

  </ListView>

  <LinearLayout

  android:orientation="horizontal"

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:layout_marginTop="6px"

  android:layout_marginBottom="8px"

  android:layout_marginLeft="8px"

  android:layout_marginRight="8px"

  android:background="#00000000">

  <ImageButton

  android:id="@+id/button"

  android:layout_width="100px"

  android:layout_height="100px"

  android:src="@android:drawable/ic_menu_add" />

  </LinearLayout>

  

7080電影網
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 廉江市| 英吉沙县| 开封市| 封开县| 白河县| 镇巴县| 大荔县| 察隅县| 威远县| 合江县| 怀柔区| 鹤山市| 德清县| 新乡县| 怀化市| 临夏市| 综艺| 离岛区| 商都县| 玉田县| 伊通| 罗城| 绩溪县| 滁州市| 丹寨县| 闽清县| 东明县| 鹤岗市| 定西市| 永济市| 涟源市| 揭西县| 宜兰县| 厦门市| 广昌县| 南汇区| 如东县| 祁连县| 洛扎县| 博客| 全州县|