package com.example.lesson3_4;

import java.util.ArrayList;
import java.util.List; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView; public class MainActivity extends Activity { // <>里面内容1.7必须 SDK>4.4 就可以不用写 List<Post> mList = new ArrayList<Post>();
// 布局中的组件
LinearLayout titles; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initData();
// 关键布局
titles = (LinearLayout) findViewById(R.id.titles);
for (int i = 0; i < mList.size(); i++) {
// 使用for创建多个TextView
TextView tv = new TextView(this);
// 分别设置值
tv.setText(mList.get(i).getTitle());
// 布局可以动态的添加多个组件
titles.addView(tv);
final Post post = mList.get(i);
tv.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// 为每一个TextView设置一个点击事件
Intent intent = new Intent(MainActivity.this,
ContentActivity.class);
// 如果需要携带数据,可以通过intent的put方法
// Bundle
// 一个对象需要传递,必须实现序列化
// 内部类访问局部变量必须final
intent.putExtra("post", post);
startActivity(intent);
}
});
} } private void initData() {
// 加载数据
for (int i = 0; i < 3; i++) {
mList.add(new Post("标题" + (i + 1), "内容" + (i + 1)));
}
}
}
package com.example.lesson3_4;

import java.io.Serializable;

public class Post implements Serializable {

    private static final long serialVersionUID = -2278908915637867413L;
String title;
String content; public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Post(String title, String content) {
super();
this.title = title;
this.content = content;
}
@Override
public String toString() {
return "Post [title=" + title + ", content=" + content + "]";
} }
package com.example.lesson3_4;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView; public class ContentActivity extends Activity { TextView title, content;
ImageView iv_back; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content);
// 关键布局组件
title = (TextView) findViewById(R.id.title);
content = (TextView) findViewById(R.id.content);
iv_back = (ImageView) findViewById(R.id.iv_back);
// 获取前一个activity传递的数据
Intent intent = getIntent();
Post post = (Post) intent.getSerializableExtra("post");
// 为布局组件设置值
title.setText(post.getTitle());
content.setText(post.getContent()); // 为ImageView设置点击事件并且返回activity
iv_back.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
finish();
}
});
} }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/titles"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lesson3_4.MainActivity" />
<?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="vertical" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp" > <TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="5dp"
android:text="标题"
android:textSize="18sp" /> <ImageView
android:id="@+id/iv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:src="@drawable/arrow_left" />
</RelativeLayout> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#CCC" /> <TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lesson3_4"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.lesson3_4.ContentActivity" >
</activity>
</application> </manifest>

android布局不带参数返回的更多相关文章

  1. httpclient post请求带参数返回数据乱码问题解决

    客户端代码: //带参数的post请求 @Test public void doPostWithParam() throws Exception { CloseableHttpClient httpC ...

  2. ajaxFileUpload上传带参数,返回值改成json格式

    /*直接复制在自己的js文件中就能使用*/ jQuery.extend({ createUploadIframe: function (id, uri) { //create frame var fr ...

  3. ionic3带参数返回原来页面

    最近用ionic3+angular4做项目.我遇到了个问题,我返回原来页面时一般都会调用this.navCtrl.pop()方法,但这个方法不能携带参数.怎么办? 可以写个回调方法. 我在a页面定义个 ...

  4. laravel重定向到上一个页面怎么带参数返回 withsucess 成功提示信息

    //控制器中 return back()->with('success','操作成功'); //with的参数1是一个session变量名,参数2为该session变量值,在视图直接这样获取 @ ...

  5. android布局带参返回

    package com.lxj.lesson2_3ID19; import com.example.lesson2_3_id19.R; import com.lxj.other.AgeActivity ...

  6. Android课程---Activity 带返回值的跳转

    Activity2.java package com.hanqi.test4; import android.content.Intent; import android.os.Bundle; imp ...

  7. java jsp调用shell(带参数)脚本并返回值

    test.jsp <%@ page language="java" import="java.util.List,java.util.ArrayList,java. ...

  8. js上传文件带参数,并且,返回给前台文件路径,解析上传的xml文件,存储到数据库中

    ajaxfileupload.js jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId ...

  9. Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)

    [Android布局学习系列]   1.Android 布局学习之——Layout(布局)详解一   2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)   3.And ...

随机推荐

  1. C语言之fileno()函数--获取已经打开的文件的文件描述符(小技巧)

    open函数相关的:  /* open 是系统调用 返回的是文件句柄*/ #include <sys/stat.h> #include <fcntl.h> int open(c ...

  2. JAVA 需要理解的重点 一

    需要理解的重点内容有: JVM内存管理机制和垃圾回收机制(基本每次面试都会问,一定要搞得透彻) JVM内存调优(了解是怎么回事,一般做项目过程中使用较多) 设计模式(熟悉常见设计模式的应用场景,会画类 ...

  3. JAVA 中的堆和栈

    栈与堆都是Java用来在Ram中存放数据的地方.与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆.     Java的堆是一个运行时数据区,类的对象从中分配空间.这些对象通过new.n ...

  4. KVM虚拟机内无agent情况下的监控方法

    KVM虚拟机内无agent情况下的监控(ceilometer实现) 今天看到大家在群里讨论KVM虚拟机的监控问题,而且是要求VM内无agent情况下的监控.这方面确实没有深入研究,但尚有些openst ...

  5. socket辅助类

    using System; using System.Collections; using System.Net; using System.Net.Sockets; using System.Tex ...

  6. iOS 中这些是否熟练掌握——(1)

    声明:本篇博文是作者原创作品.参考1  参考2  参考3  参考4  参考5  参考6 关于网上一些关于iOS资料,自己通过学习做了一些整理,这里仅仅作为笔记,方便自己学习使用,加深理解. 1.什么是 ...

  7. WebBrowser内嵌页面的跨域调用问题

    很早之前我写过一篇Blog:网页通过External接口与WebBrowser交互,文中的交互其实只介绍了JS调用C++的部分,而C++调用JS由于微软自己的例子太多,那篇文章就没介绍,不过我最近遇到 ...

  8. 在调试javascript的时候,要常使用alert()

    在调试javascript的时候,要常使用alert()会帮助我们定位脚本错误.

  9. easyui datagrid 列对不齐

    function initBIRDataGrid(id,cols){ $('#basicTable').datagrid({ //列表区域 pageList: [5, 10, 15], fit:tru ...

  10. 纯css单选框

    1.没有用bootstrap时: .has_sel,.un_sel{display:block; width:16px; height: 16px; border: 1px solid #B06A50 ...