Android layout does not contain parameters returned. android layout Parameters

Source: Internet
Author: User

Android layout does not contain parameters returned. android layout Parameters

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 {// <> content 1.7 must be SDK> 4.4. You do not need to write List <Post> mList = new ArrayList <Post> (); // The LinearLayout titles component in the layout; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initData (); // key layout titles = (LinearLayout) findViewById (R. id. titles); for (int I = 0; I <mList. size (); I ++) {// use for to create multiple TextView TV = new TextView (this); // set the value TV respectively. setText (mList. get (I ). getTitle (); // You can dynamically add Multiple widgets to the layout. addView (TV); final Post post = mList. get (I); TV. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// set Intent intent = new Intent (MainActivity) for each TextView. this, ContentActivity. class); // If You Need To carry data, you can use the put Method of intent // Bundle // an object to be passed. serialization is required. // for internal class access, local variables must be final intent. putExtra ("post", post); startActivity (intent) ;}}}private void initData () {// load data for (int I = 0; I <3; I ++) {mList. add (new Post ("title" + (I + 1), "content" + (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); // key layout component title = (TextView) findViewById (R. id. title); content = (TextView) findViewById (R. id. content); iv_back = (ImageView) findViewById (R. id. iv_back); // obtain the data Intent intent = getIntent (); Post post = (Post) intent. getSerializableExtra ("post"); // set the title for the layout component. setText (post. getTitle (); content. setText (post. getContent (); // set the click event for ImageView and return 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 = "title" 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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.