`
ping8080
  • 浏览: 58149 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
文章分类
社区版块
存档分类
最新评论

处女apk纠结过的技术点<4>

阅读更多

                                                       listView布局自定义和数据填充,以及结合tabhost使用

1,tabhost定义选项

LayoutInflater.from(this).inflate(R.layout.pressure,
    host.getTabContentView(), true);
  // 加载tab选项字体布局
  LayoutInflater inflater = this.getLayoutInflater();
  View view1 = inflater.inflate(R.layout.tabview1, null);
  View view2 = inflater.inflate(R.layout.tabview2, null);
  View view3 = inflater.inflate(R.layout.tabview3, null);
  View view4 = inflater.inflate(R.layout.tabview4, null);
  View view5 = inflater.inflate(R.layout.tabview5, null);
  View view6 = inflater.inflate(R.layout.tabview6, null);//自定义view填充到选项卡中,改变选项卡风格

  host.addTab(host.newTabSpec("7days").setIndicator(view1)
    .setContent(R.id.pressure));
  host.addTab(host.newTabSpec("15days").setIndicator(view2)
    .setContent(R.id.pressure));
  host.addTab(host.newTabSpec("30days").setIndicator(view3)
    .setContent(R.id.pressure));
  host.addTab(host.newTabSpec("90days").setIndicator(view4)
    .setContent(R.id.pressure));
  host.addTab(host.newTabSpec("180days").setIndicator(view5)
    .setContent(R.id.pressure));
  host.addTab(host.newTabSpec("360days").setIndicator(view6)
    .setContent(R.id.pressure));
  setContentView(host);//设置host为主布局

2,在tabhost选项中设置一直线布局为为显示视图,而布局中填充,列表选项和一个listview

<?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="fill_parent"
 android:orientation="vertical"
 android:id="@+id/pressure">
 <LinearLayout android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:orientation="horizontal">
  <TextView android:layout_width="140dip" android:layout_height="wrap_content"
   android:text="@string/tab1" android:textColor="@color/frontcolor"
   android:textSize="20sp"/>
  <TextView android:layout_width="150dip" android:layout_height="wrap_content"
   android:text="@string/tab2" android:textColor="@color/frontcolor"
   android:textSize="20sp"/>
  <TextView android:layout_width="50dip" android:layout_height="wrap_content"
   android:text="@string/tab3" android:textColor="@color/frontcolor"
   android:textSize="20sp"/>
  <TextView android:layout_width="150dip" android:layout_height="wrap_content"
   android:text="@string/tab4" android:textColor="@color/frontcolor"
   android:textSize="20sp"/>
  <TextView android:layout_width="220dip" android:layout_height="wrap_content"
   android:text="@string/tab5" android:textColor="@color/frontcolor"
   android:textSize="20sp"/>
  <TextView android:layout_width="120dip" android:layout_height="wrap_content"
   android:text="@string/tab6" android:textColor="@color/frontcolor"
   android:textSize="20sp"/>
 </LinearLayout>
 <ListView android:id="@+id/pressureData" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:layout_weight="1" />
</LinearLayout>

 

tab选项卡中view视图布局

 

 

3,设置listview的布局

 

 

 

<?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="fill_parent"
 android:orientation="horizontal">
 <TextView android:id="@+id/tx1"  android:layout_width="140dip"
  android:layout_height="wrap_content" android:text=""
  android:textColor="@color/white" android:textSize="20sp"/>
 <TextView android:id="@+id/tx2" android:layout_width="150dip"
  android:layout_height="wrap_content" android:text=""
  android:textColor="@color/white" android:textSize="20sp"/>
 <TextView android:id="@+id/tx3" android:layout_width="50dip"
  android:layout_height="wrap_content" android:text=""
  android:textColor="@color/white" android:textSize="20sp"/>
 <TextView android:id="@+id/tx4" android:layout_width="150dip"
  android:layout_height="wrap_content" android:text=""
  android:textColor="@color/white" android:textSize="20sp"/>
 <TextView android:id="@+id/tx5" android:layout_width="220dip"
  android:layout_height="wrap_content" android:text=""
  android:textColor="@color/white" android:textSize="20sp"/>
 <TextView android:id="@+id/tx6" android:layout_width="120dip"
  android:layout_height="wrap_content" android:text=""
  android:textColor="@color/white" android:textSize="20sp"/>
</LinearLayout>
主视图下的一个listview中填充的小view

 

4,获取要填充的数据填充到listview中去

 

//自定义适配器

public class PressureAdapter extends BaseAdapter {
  Context mContext;
  JSONArray jsonObj;

  public PressureAdapter(Context mContext, JSONArray jsonObj) {
   super();
   this.mContext = mContext;
   this.jsonObj = jsonObj;
  }

  @Override
  public int getCount() {
   return jsonObj.length();
  }

  @Override
  public Object getItem(int position) {
   return position;
  }

  @Override
  public long getItemId(int position) {
   return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   LayoutInflater mInflater = getLayoutInflater();
   View view = mInflater.inflate(R.layout.pressure_data, null);
   TextView tx1 = (TextView) view.findViewById(R.id.tx1);//获取listview布局中的view子项ID并且赋值
   TextView tx2 = (TextView) view.findViewById(R.id.tx2);
   TextView tx3 = (TextView) view.findViewById(R.id.tx3);
   TextView tx4 = (TextView) view.findViewById(R.id.tx4);
   TextView tx5 = (TextView) view.findViewById(R.id.tx5);
   TextView tx6 = (TextView) view.findViewById(R.id.tx6);
   try {
    tx1.setText(jsonObj.getJSONObject(position).getString(
      "systolic"));
    tx2.setText(jsonObj.getJSONObject(position).getString(
      "diastolic"));
    tx3.setText(jsonObj.getJSONObject(position).getString("pulse"));
    tx4.setText(jsonObj.getJSONObject(position).getString(
      "bodyTemperature"));
    tx5.setText(jsonObj.getJSONObject(position).getString(
      "dateTime"));
    tx6.setText(jsonObj.getJSONObject(position).getString("tcText"));
   } catch (JSONException e) {

    e.printStackTrace();
   }
   return view;
  }
 }

 

附带:

list = (ListView) findViewById(R.id.pressureData);
  host.setCurrentTab(0);  //设置当前被选中选项
  list.setAdapter(createAdapter("7"));
  host.setOnTabChangedListener(new OnTabChangeListener() {

   @Override
   public void onTabChanged(String tabId) {//选项切换事件
    if (host.getCurrentTab() == 0) {         
     list.setAdapter(createAdapter("7"));
    }
    if (host.getCurrentTab() == 1) {         
     list.setAdapter(createAdapter("15"));
    }
    if (host.getCurrentTab() == 2) {       
     list.setAdapter(createAdapter("30"));
    }
    if (host.getCurrentTab() == 3) {     
     list.setAdapter(createAdapter("90"));
    }
    if (host.getCurrentTab() == 4) {     
     list.setAdapter(createAdapter("180"));
    }
    if (host.getCurrentTab() == 5) {
     list.setAdapter(createAdapter("360"));
    }
   }
  });

分享到:
评论

相关推荐

    Android View Animations

    &lt;type&gt;apklib&lt;/type&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.daimajia.easing&lt;/groupId&gt; &lt;artifactId&gt;library&lt;/artifactId&gt; &lt;version&gt;1.0.1&lt;/version&gt; &lt;type&gt;apklib&lt;/type&gt; &lt;/dependency&gt; Eclipse Download...

    csgate.apk

    &lt;ModuleID&gt;4&lt;/ModuleID&gt; &lt;User&gt;sarena76@naver.com&lt;/User&gt; &lt;Passwd&gt;&lt;/Passwd&gt; &lt;MsgSeq&gt;0000000001&lt;/MsgSeq&gt; &lt;DeviceToken&gt;&lt;/DeviceToken&gt; &lt;VoipToken&gt;&lt;/VoipToken&gt; &lt;FcmToken&gt;fgFEl367nCg:APA91bFMguX-4...

    无线局域网

    Characteristics IEEE 802.11 PHY MAC Roaming .11a, b, g, HIPERLAN Standards overview HiperLAN2 QoS Bluetooth Comparison

    AndroidLabeledEditText:带有嵌入式标签的EditText小部件

    &lt;type&gt;apklib&lt;/type&gt; &lt;version&gt;xxx&lt;/version&gt; &lt;/dependency&gt; 用法 将一个新的名称空间属性添加到您的根布局容器。 xmlns:app="http://schemas.android.com/apk/res-auto" 就像其他任何EditText小部件一样,添加并...

    Android动画AndroidViewAnimations.zip

     &lt;type&gt;apklib&lt;/type&gt; &lt;/dependency&gt; &lt;dependency&gt;  &lt;groupId&gt;com.daimajia.easing&lt;/groupId&gt;  &lt;artifactId&gt;library&lt;/artifactId&gt;  &lt;version&gt;1.0.1&lt;/version&gt;  &lt;type&gt;apklib&lt;/type&gt; &lt;/dependency&gt;...

    apkpatch-1.0.3.zip

    usage: apkpatch -f &lt;new&gt; -t &lt;old&gt; -o &lt;output&gt; -k &lt;keystore&gt; -p &lt;***&gt; -a &lt;alias&gt; -e &lt;***&gt; -a,--alias &lt;alias&gt; keystore entry alias. -e,--epassword &lt;***&gt; keystore entry password. -f,--from &lt;loc&gt; new ...

    uniread-1.01.tar.gz

    Linux上使用SQL*Plus有一个相当不方便的...&lt;br&gt;答案是安装一个小工具:Uniread&lt;br&gt;&lt;br&gt;安装Uniread的要求&lt;br&gt;&lt;br&gt;1.Linux系统上必须已经安装了Perl&lt;br&gt;2.安装Uniread之前先安装 readline,Term,IO这3个工具。&lt;br&gt;&lt;br&gt;

    android无线调试

    1root,2安装apk并运行,3打开as进入terminal输入adb connect 192.168.1.xxx(运行软件后的地址),http://blog.csdn.net/ln840434235/article/details/53022221如果找不到adb命令,则看这篇文章...

    apktool 反编译工具 稳定 绿色 最新

    &lt;file.apk&gt;代表了要反编译的apk文件的路径,最好写绝对路径,比如C:\MusicPlayer.apk &lt;dir&gt;代表了反编译后的文件的存储位置,比如C:\MusicPlayer 如果你给定的&lt;dir&gt;已经存在,那么输入完该命令后会提示你,并且无法...

    TinyCC编译器

    TinyCC编译器 &lt;br&gt;发布时间:2007-07-09 12:28 网友评论 0 条 &lt;br&gt;软件大小:419kb&lt;br&gt;软件类别:编译开发&lt;br&gt;点击次数:1&lt;br&gt;软件语言:英文&lt;br&gt;运行环境:Win9X,Me,NT,2000,XP,2003,Unix&lt;br&gt;软件评级:4&lt;br&gt;更新...

    android P 9.0添加Ethernet功能(settings+framework).zip

    &lt;br&gt;res\xml\network_and_internet.xml res\drawable\ic_ethernet_cell.xml &lt;br&gt;res\values\strings.xml res\xml\ethernet_settings.xml &lt;br&gt;res\xml\ethernet_static_ip.xml &lt;br&gt;src\...

    sd卡女佣最新v2.04已付费汉化中文版apk

    sd卡女佣最新v2.04已付费汉化中文版

    apkpatch1.0.3阿里热更新工具以及使用说明.zip

     usage: apkpatch -f &lt;new&gt; -t &lt;old&gt; -o &lt;output&gt; -k &lt;keystore&gt; -p &lt;***&gt; -a &lt;alias&gt; -e &lt;***&gt;  -a,--alias &lt;alias&gt; keystore entry alias.  -e,--epassword &lt;***&gt; keystore entry password.  -f,--from ...

    Android代码-Android

    &lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt; 74b5821d0edd407b74087d33f303bd617a733ca6 Para poder utilizar este programa sera necesario descargar e instalar un archivo .apk en el dispositivo con el sistema operativo atras mencionado....

    apk-parser:适用于Java的APK解析器

    &lt; artifactId&gt;apk-parser&lt;/ artifactId&gt; &lt; version&gt;2.6.10&lt;/ version&gt; &lt;/ dependency&gt; 从2.0版开始,apk解析器需要Java7。支持Java 6的最新版本是1.7.4。 用法 普通的方法是使用ApkFile类,该类包含获取...

    Android软件自动更新实现代码

    &lt;name&gt;baiduxinwen.apk&lt;/name&gt; &lt;url&gt;http://gdown.baidu.com/data/wisegame/e5f5c3b8e59401c8/baiduxinwen.apk&lt;/url&gt; &lt;/update&gt; 2、在客户端实现更新操作 涉及到三个技术:  1.xml文件的解析  2....

    飛鴿傳書2.5

    可运行于多种操作平台(Win/Mac/UNIX/Java), 并实现跨平台信息交流.&lt;br&gt;- 不需要服务器支持.&lt;br&gt;- 支持文件/文件夹的传送 (2.00版以上)&lt;br&gt;- 通讯数据采用 RSA/Blofish 加密 (2.00版以上)&lt;br&gt;- 十分小巧, 简单易用, ...

    tractor-maven-plugin:Amazon Device Farm测试执行和结果管理Maven插件

    拖拉机Maven插件 Amazon Device Farm测试执行和结果管理Maven... &lt;uploadApplicationFilename&gt;app-debug.apk&lt;/uploadApplicationFilename&gt; &lt;uploadTestFilename&gt;framework-zip-with-dependencies.zip&lt;/uploadTest

    java解决zip乱码,查看apk包的包名

    压缩文档: java -jar spanner.jar zip &lt;path&gt; &lt;file&gt; ...查看apk信息: java -jar apk &lt;file&gt; 查看apk包名: java -jar info &lt;path | file&gt; 查看MD5:  java -jar md5 &lt;file&gt; 解压缩文档主要解决在linux下的乱码问题

    apktool_2.3.0.jar

    &lt;file.apk&gt;代表了要反编译的apk文件的路径,最好写绝对路径,比如C:\MusicPlayer.apk &lt;dir&gt;代表了反编译后的文件的存储位置,比如C:\MusicPlayer 如果你给定的&lt;dir&gt;已经存在,那么输入完该命令后会提示你,并且...

Global site tag (gtag.js) - Google Analytics