如何使用列表视图来填充表格布局 [英] How to use listview to populate a table layout

查看:102
本文介绍了如何使用列表视图来填充表格布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从蓝牙以下code聊天的例子。所有我希望做的是把数据通过蓝牙并将其显示在不断地在正确的地方在表格布局字符串。由于大部分的BT例子是为我做的,但改变布局在主文件没有奏效。我是采取正确的方法,或做我需要做一个全新的适配器来处理我的数据和布局的要求?据我所知,code的方式,数据被放入同R.layout.message格式的数组,然后R.id.in告诉程序如何显示信息。我需要为我想要显示从阵列中的数据每个单元一个单独的字段ID?我AP preciate任何帮助,您可以给我。

I have the following code from the Bluetooth chat example. All I am looking to do is take the data in over bluetooth and display it as strings in the right place constantly in the table layout. Thanks to the BT example most of it is done for me, but changing the layout in the main file has not worked. Am I taking the right approach, or do I need to make a whole new adapter to handle my data and layout requirements? The way I understand the code, the data is being put into an array with the R.layout.message format and then the R.id.in is telling the program how to display the info. Do I need a separate field ID for each cell I want to display the data from the array in? I appreciate any help you can give me.

 // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
    mConversationView = (ListView) findViewById(R.id.in);
    mConversationView.setAdapter(mConversationArrayAdapter);

从layout.message文件

From the layout.message file

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#A4C639"
android:textSize="18sp"

/>

从layout.main文件

From the layout.main file

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1,2">

<TableRow>
    <TextView
        android:layout_column="1"
        android:text="RPM"
        android:padding="3dip" 
        android:textSize="18sp"
        />
    <TextView
         android:layout_column="1"
        android:text="Gear"
        android:gravity="left"
        android:padding="3dip"
        android:textSize="24sp"
         />
          <TextView
        android:layout_column="1"
        android:text="Temp"
        android:gravity="right"
        android:padding="3dip" 
        android:textSize="18sp"
        />
</TableRow>
   <TableRow>

     <ListView android:id="@+id/in"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:layout_weight="1"
/>
    <TextView
        android:layout_column="1"
        android:text=""
        android:gravity="right"
        android:padding="3dip" 
        android:textSize="18sp"
        />
           <ListView android:id="@+id/in"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:layout_weight="1"
/>

<TableRow>

    <TextView
         android:layout_column="1"
        android:text="MPH"
        android:padding="3dip" 
        android:textSize="18sp"
        />
          <ListView android:id="@+id/in"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:layout_weight="1"
/>
    <TextView
        android:layout_column="1"
        android:text="Battery Voltage"
        android:gravity="right"
        android:padding="3dip" 
        android:textSize="18sp"
        />


  
        

    android:layout_weight="1"
/>
    <TextView
        android:layout_column="1"
        android:text=""
        android:gravity="right"
         android:padding="3dip" 
        android:textSize="18sp"
        />
         <ListView android:id="@+id/in"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:layout_weight="1"
/>
         </TableRow>


        
             
        
   
    
           
             
           
   

<!--   
<ListView android:id="@+id/in"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stackFromBottom="false"
    android:transcriptMode="disabled"
    android:layout_weight="1"
/>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <EditText android:id="@+id/edit_text_out"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="bottom"
    />
    <Button android:id="@+id/button_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/send"
    />
</LinearLayout>
-->

推荐答案

开始尝试用的的ListView教程。由于使用复杂的意见,行,你最终会需要重写的 getView 方法的 ArrayAdapter 吹大排布置,并适当设置其意见。

Try starting with the ListView tutorial. Since you are using complicated views as rows, you will eventually need to override the getView method on your ArrayAdapter to inflate the row layout and set its views appropriately.

这篇关于如何使用列表视图来填充表格布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆