国产探花免费观看_亚洲丰满少妇自慰呻吟_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電影網
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石狮市| 错那县| 申扎县| 井冈山市| 翁牛特旗| 报价| 东至县| 丹棱县| 若尔盖县| 凉山| 西城区| 宜川县| 昆明市| 巴中市| 织金县| 长丰县| 安陆市| 德化县| 清涧县| 泰安市| 永丰县| 准格尔旗| 尼勒克县| 理塘县| 房产| 珲春市| 边坝县| 西贡区| 浠水县| 文山县| 开鲁县| 夹江县| 伊金霍洛旗| 井研县| 陆川县| 峡江县| 新宾| 当雄县| 定陶县| 综艺| 蕉岭县|