任务2:选项卡组件和ListView组件结合模拟新浪微博
2014-04-26 21:10
441 查看
【程序截屏】
![](http://img.blog.csdn.net/20140427095905062?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbW9vbjk0MDMxMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
一、
二、
三、
四、
五、
六、
七、
八、
一、
package com.example.ui2; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.widget.TabHost; public class MainActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); TabHost tabHost=getTabHost(); LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true); Intent intent=new Intent(); intent.setClass(this, Tab01Activity.class); tabHost.addTab(tabHost .newTabSpec("tab1") .setIndicator("", getResources().getDrawable(R.drawable.p1)) .setContent(intent)); tabHost.addTab(tabHost .newTabSpec("tab2") .setIndicator("", getResources().getDrawable(R.drawable.p2)) .setContent(R.id.tab2)); tabHost.addTab(tabHost .newTabSpec("tab3") .setIndicator("", getResources().getDrawable(R.drawable.p3)) .setContent(R.id.tab3)); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
二、
package com.example.ui2; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; public class Tab01Activity extends Activity { private List<Map<String, ?>> data; private ListView listItem; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab1_main); listItem = (ListView) this.findViewById(R.id.list); data = getData(); SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.tab1_item, new String[] { "image", "name", "publish", "content" }, new int[] { R.id.image, R.id.name, R.id.publish, R.id.content }); listItem.setAdapter(adapter); listItem.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { // TODO Auto-generated method stub Map<String, Object> item = (Map<String, Object>) data .get(position); Toast.makeText(getApplicationContext(), item.get("name") + "\n\n" + item.get("content"), Toast.LENGTH_LONG).show(); } }); } private List<Map<String, ?>> getData() { List<Map<String, ?>> data = new ArrayList<Map<String, ?>>(); Map<String, Object> item = new HashMap<String, Object>(); item.put("image", R.drawable.p1); item.put("name", "想想"); item.put("publish", "1分钟前"); item.put("content", "我正在学习安卓Listview。嘎嘎嘎嘎嘎嘎嘎"); data.add(item); item = new HashMap<String, Object>(); item.put("image", R.drawable.p2); item.put("name", "嘻嘻"); item.put("publish", "10分钟前"); item.put("content", "今天很高兴阿!"); data.add(item); item = new HashMap<String, Object>(); item.put("image", R.drawable.p3); item.put("name", "丽丽"); item.put("publish", "5分钟前"); item.put("content", "今天遇见一件好玩的事情。"); data.add(item); item = new HashMap<String, Object>(); item.put("image", R.drawable.p4); item.put("name", "西西"); item.put("publish", "2分钟前"); item.put("content", "今天天气真好哈!"); data.add(item); item = new HashMap<String, Object>(); item.put("image", R.drawable.p5); item.put("name", "露露"); item.put("publish", "10分钟前"); item.put("content", "今天真高兴阿!"); data.add(item); item = new HashMap<String, Object>(); item.put("image", R.drawable.p6); item.put("name", "美美"); item.put("publish", "2分钟前"); item.put("content", "今天真高兴阿!"); data.add(item); item = new HashMap<String, Object>(); item.put("image", R.drawable.p7); item.put("name", "晕晕"); item.put("publish", "5分钟前"); item.put("content", "今天真高兴阿!"); data.add(item); return data; } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
三、
/** Automatically generated file. DO NOT MODIFY */ package com.example.ui2; public final class BuildConfig { public final static boolean DEBUG = true; }
四、
/* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */ package com.example.ui2; public final class R { public static final class attr { } public static final class dimen { /** Default screen margins, per the Android Design guidelines. Customize dimensions originally defined in res/values/dimens.xml (such as screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. */ public static final int activity_horizontal_margin=0x7f040000; public static final int activity_vertical_margin=0x7f040001; } public static final class drawable { public static final int ic_launcher=0x7f020000; public static final int p1=0x7f020001; public static final int p10=0x7f020002; public static final int p2=0x7f020003; public static final int p3=0x7f020004; public static final int p4=0x7f020005; public static final int p5=0x7f020006; public static final int p6=0x7f020007; public static final int p7=0x7f020008; public static final int p8=0x7f020009; public static final int p9=0x7f02000a; } public static final class id { public static final int action_settings=0x7f080007; public static final int content=0x7f080005; public static final int image=0x7f080002; public static final int list=0x7f080006; public static final int name=0x7f080003; public static final int publish=0x7f080004; public static final int tab2=0x7f080000; public static final int tab3=0x7f080001; } public static final class layout { public static final int activity_tab01=0x7f030000; public static final int main=0x7f030001; public static final int tab1_item=0x7f030002; public static final int tab1_main=0x7f030003; } public static final class menu { public static final int main=0x7f070000; public static final int tab01=0x7f070001; } public static final class string { public static final int action_settings=0x7f050001; public static final int app_name=0x7f050000; public static final int hello_world=0x7f050002; public static final int title_activity_tab01=0x7f050003; } public static final class style { /** Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. Base application theme for API 11+. This theme completely replaces AppBaseTheme from res/values/styles.xml on API 11+ devices. API 11 theme customizations can go here. Base application theme for API 14+. This theme completely replaces AppBaseTheme from BOTH res/values/styles.xml and res/values-v11/styles.xml on API 14+ devices. API 14 theme customizations can go here. */ public static final int AppBaseTheme=0x7f060000; /** Application theme. All customizations that are NOT specific to a particular API-level can go here. */ public static final int AppTheme=0x7f060001; } }
五、
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Tab01Activity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
六、
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/tab2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/p2"/> <ImageView android:id="@+id/tab3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/p3"/> </RelativeLayout>
七、
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ImageView android:id="@+id/image" android:padding="10dp" android:layout_width="48dp" android:layout_height="48dp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/name" android:paddingTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/publish" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="10dp" android:gravity="right" /> </LinearLayout> <TextView android:id="@+id/content" android:paddingTop="10dp" android:paddingBottom="10dp" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
八、
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout>
相关文章推荐
- Android UI 设计 选项卡组件和ListView组件结合模拟新浪微博
- 选项卡组件和ListView组件结合模拟新浪微博
- Android程序——选项卡组件和ListView组件结合模拟新浪微博
- 选项卡组件和ListView组件结合模拟新浪微博
- 《选项卡组件和ListView组件结合模拟新浪微博》
- 选项卡组件和ListView组件结合模拟新浪微博
- ListView组件的应用(模拟新浪微博界面)
- react-native组件中NavigatorIOS和ListView结合使用的方法
- listview组件的应用—模拟微博
- android结合异步任务,动态加载图片,Json解析数据展示在ListView,并且实现按日期分类展示,借口回调
- listview组件的应用模拟微博
- TabHost组件和ListView组件的结合使用
- Android - SimpleAdapter适配器支持的组件及Listview模拟下载
- android滑动组件嵌套一般思路,多任务手势思路,触摸传递思路,【例】listview嵌套viewpager
- ListView应用之模拟新浪微博界面
- android: listview组件的应用-模拟微博
- Tab组件和其他组件结合使用(含ListView)
- Android学习12——Tab组件和ListView组件结合
- 一看就会Android之列表视图组件ListView结合Adapter的使用及监听
- 动态组件(可模拟选项卡)