Android:HTML等效

时间:2011-06-25 16:06:48

标签: android listview android-listview tablelayout

我有以下HTML / Javascript(下面列出。使用ListView或TableLayout / TableRow的Android的等效代码是什么。


<style type="text/css">
.normal { background-color:#000; color:#FFFF00 }
.highlight { background-color:#FFFF00; color:#000 }
</style>
<center>
<font face="arial">
<table cellpadding="5" border="1" bordercolor="white">
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
        <td>My test1</td>   
    </tr> 
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
        <td>My test2</td>   
    </tr>
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
        <td>My test3</td>   
    </tr> 
</table>

这是我尝试过的......但我似乎无法获得上面的相同输出。我错过了使这个Android代码与上面的HTML代码匹配?


<?xml version="1.0" encoding="utf-8"?> 
<resources>     
    <color name="white">#fff</color>     
    <color name="black">#000</color>     
    <color name="yellow">#FFFF00</color>
    <style name="listtableview">         
        <item name="android:layout_height">wrap_content</item>         
        <item name="android:layout_width">fill_parent</item>         
        <item name="android:textSize">15dip</item>         
        <item name="android:padding">5dip</item>       
        <item name="android:textAppearance">@android:style/TextAppearance.Medium</item>         
        <item name="android:shadowColor">@color/yellow</item>         
        <item name="android:shadowRadius">1</item>         
        <item name="android:shadowDy">1</item>         
        <item name="android:textStyle">bold</item>         
        <item name="android:textColor">@color/white</item>         
        <item name="android:background">@color/black</item>     
    </style>  
</resources>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent"  
    android:layout_width="fill_parent" 
    android:background="@color/black"
    android:orientation="vertical" > 
    <TableRow android:background="@color/black" 
            android:soundEffectsEnabled="true">
        <Button
            android:id="@+id/item_test"
                        style="@style/listtableview"  />
                      <Button
            android:id="@+id/item_id"
                        style="@style/listtableview"  />

    </TableRow> 
</TableLayout> 

此处的实施代码:


package com.yama.android.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yama.android.test.R;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends ListActivity 
{       
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_empty);        

        ArrayList> list = new ArrayList>();                  

        for (int i = 0; i  map = new HashMap();  
            map.put(i, "My Test" + i);
            list.add(map);  
        }

        @SuppressWarnings("unchecked")
        ListAdapter adapter = new SimpleAdapter(this, (List>) list, R.layout.list_table,
                        new String[] {"t1", "t2"}, 
                        new int[] { R.id.item_test, R.id.item_id });

        setListAdapter(adapter);        

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);  
        lv.setLongClickable(true);
        lv.setOnItemClickListener(new OnItemClickListener() 
        {
            public void onItemClick(AdapterView parent, View view, int position, long id) 
            {               
                @SuppressWarnings("unchecked")
        HashMap link = (HashMap) lv.getItemAtPosition(position);
        //TODO: more code goes here
    }
        });        
    }
}

0 个答案:

没有答案