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

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

a-ndroid動態布局之動態加入TextView和ListView的方法

2019-11-02 14:49:19
字體:
來源:轉載
供稿:網友

   本文實例講述了android動態布局之動態加入TextView和ListView的方法。分享給大家供大家參考。具體實現方法如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
琪琪影院[www.aikan.tv/special/qiqiyingyuan/]
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 package org.guoshi; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.guoshi.adapter.ImageAndTextAdapter; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.LinearLayout; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; public class Main extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.friend_info_view); final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.groups); final ListView lv = new ListView(this); List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map.put("title", "jayqean"); map.put("imgsrc", R.drawable.icon); data.add(map); ListAdapter adapter = new ImageAndTextAdapter(Main.this, data, R.layout.chats_view_item, new String[] { "title", "imgsrc" }, new int[] { R.id.chats_view_name, R.id.chats_view_item_image }); lv.setAdapter(adapter); final TextView tv1 = new TextView(this); tv1.setText("常用聯系人"); tv1.setId(1); final RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); lp1.addRule(RelativeLayout.BELOW, R.id.groups); tv1.setLayoutParams(lp1); tv1.setBackgroundColor(R.color.group_view_background); tv1.setOnClickListener(new OnClickListener() { boolean flag = false; @Override public void onClick(View v) { // TODO Auto-generated method stub Log.d("tag", tv1.getText().toString()); if(!flag){ linearLayout.addView(lv, linearLayout.indexOfChild(tv1) + 1); // lp1.addRule(RelativeLayout.BELOW, 1); // linearLayout.addView(lv, lp1); flag = true; } else{ linearLayout.removeView(lv); flag = false; } } }); linearLayout.addView(tv1, lp1); // 線性布局 通過參數index控制加入的控件的位置 // ------------------------ // 加入分割線 final TextView line = new TextView(this); line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1)); line.setBackgroundColor(Color.WH
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳曲县| 北海市| 吉水县| 西和县| 咸宁市| 永州市| 蕉岭县| 扶沟县| 锦屏县| 平顺县| 沾化县| 从江县| 鲁山县| 松潘县| 化德县| 安仁县| 隆安县| 内黄县| 葫芦岛市| 和政县| 广南县| 宜丰县| 合江县| 凤庆县| 水富县| 景德镇市| 循化| 贡嘎县| 淮北市| 富顺县| 邢台市| 色达县| 蒲城县| 郎溪县| 临城县| 古浪县| 湄潭县| 南京市| 额尔古纳市| 苍溪县| 阜城县|