Android程序——选项卡组件和ListView组件结合模拟新浪微博

 

结果图如下:

MainActivity.java

package com.example.task2.activity;

import android.os.Bundle;  
import android.app.TabActivity;  
import android.content.Intent;  
import android.content.res.Resources;  
import android.view.Menu;  
import android.widget.TabHost;  
import android.widget.TabHost.TabSpec;  
public class MainActivity extends TabActivity {

	TabHost tabHost;  
	    TabSpec tabSpec01,tabSpec02,tabSpec03; 
	    Intent intent01,intent02,intent03;  
	    @SuppressWarnings("deprecation")  
	    @Override  
	    protected void onCreate(Bundle savedInstanceState) {  
	       super.onCreate(savedInstanceState);  
	        setContentView(R.layout.activity_tab);  
	         
	         tabHost=getTabHost();    
	         intent01 = new Intent(this, One.class);  
	         intent02 = new Intent(this, Two.class);  
	         intent03= new Intent(this, Three.class); 
	         tabSpec01 = tabHost.newTabSpec("system").setIndicator("Blog",null).  
	                                                                              
	                    setContent(intent01);        
	         tabSpec02 = tabHost.newTabSpec("hardware").setIndicator("Test",null).  
	                    setContent(intent02);  
	         
	         tabSpec03 =tabHost.newTabSpec("apple").setIndicator("bag",null).
	        		    setContent(intent03);
	              
	         tabHost.addTab(tabSpec01);    
	         tabHost.addTab(tabSpec02); 
	         tabHost.addTab(tabSpec03); 
	            
	         tabHost.setCurrentTab(0);  
	          
	          
	    }  
	  
}  
   
one.java

package com.example.task2.activity;

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

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class One extends Activity {

	private ListView listView;
	List<Map<String, ?>> data;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_one);
		listView = (ListView)findViewById(R.id.lv);
		SimpleAdapter simpleAdapter = new SimpleAdapter(One.this, getData(), R.layout.blog, new String[]{
			"name","address","photo"}, new int[]{R.id.name,R.id.wenzi,R.id.photo});

		
		listView.setAdapter(simpleAdapter);
		
	}
	
	 public List<Map<String, ?>> getData() {
	        data = new ArrayList<Map<String, ?>>();
	        Map<String, Object> data01 = new HashMap<String, Object>();
	        data01.put("name", "云影");
	        data01.put("address", "今天心情不错,天气也挺好");
	        data01.put("photo",R.drawable.aabb);
	        data.add(data01);
	        data01 = new HashMap<String, Object>();
	        data01.put("name", "星星");
	        data01.put("address", "好想去马尔代夫旅游啊");
	        data01.put("photo",R.drawable.aabb);
	        data.add(data01);
	        data01 = new HashMap<String, Object>();
	        data01.put("name", "月亮");
	        data01.put("address", "超级喜欢金秀贤");
	        data01.put("photo",R.drawable.aabb);
	        data.add(data01);
	        data01 = new HashMap<String, Object>();
	        data01.put("name", "宁远");
	        data01.put("address", "今天想吃肉");
	        data01.put("photo",R.drawable.aabb);
	        data.add(data01);
	        return data;
	    }

	 
	 
}
	 

Two.java

package com.example.task2.activity;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class Two extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_two);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.two, menu);
		return true;
	}

}

Three.java

package com.example.task2.activity;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class Three extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_three);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.three, menu);
		return true;
	}

}
布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/photo"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="10dp" />

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@id/photo"
        android:text="" />

    <TextView
        android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/name"
        android:layout_marginLeft="130dp"
        android:layout_marginTop="20dp"
        android:text="1分钟前" />
    
    <TextView 
        android:id="@+id/wenzi"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:layout_toRightOf="@id/photo"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        android:text=""/>

</RelativeLayout>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值