午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    安卓開發(fā)中動態(tài)添加lsitView 代碼實例
    來源:易賢網(wǎng) 閱讀:1166 次 日期:2014-08-21 16:12:42
    溫馨提示:易賢網(wǎng)小編為您整理了“安卓開發(fā)中動態(tài)添加lsitView 代碼實例”,方便廣大網(wǎng)友查閱!

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

    喚醒一下,其實這個喚醒也就是在button下用 或者在別的控件下調(diào)用 如果是在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>

    <LinearLayout

    android:orientation="vertical"

    android:layout_width="230px"

    android:layout_height="wrap_content"

    android:layout_marginTop="8px"

    android:layout_marginBottom="8px"

    android:layout_marginLeft="0px"

    android:layout_marginRight="28px"

    android:background="#cccccc00" >

    <EditText android:id="@+id/new_value_field"

    android:textColor="#020905"

    android:textSize="18sp"

    android:layout_marginTop="6px"

    android:layout_marginBottom="8px"

    android:layout_marginLeft="12px"

    android:layout_marginRight="12px"

    android:layout_width="210px"

    android:layout_height="wrap_content"

    android:layout_weight="1"/>

    </LinearLayout>

    </LinearLayout>

    ROw:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:background="#00000000">

    <TextView

    android:id="@+id/list_value"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    />

    </LinearLayout>

    更多信息請查看IT技術(shù)專欄

    更多信息請查看網(wǎng)絡編程
    易賢網(wǎng)手機網(wǎng)站地址:安卓開發(fā)中動態(tài)添加lsitView 代碼實例

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)