Android4.0.4编程日记(4)--List单击Intent跳转并获取数据

第二个页面的代码
package com.example.test;


import com.example.pojo.Params;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class SecondActivity extends Activity{
	TextView name;
	TextView note;
	ToggleButton controlButton;
	String id;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_second);
		name=(TextView) this.findViewById(R.id.itemNameValue);
		note=(TextView) this.findViewById(R.id.itemNoteValue);
		controlButton=(ToggleButton) this.findViewById(R.id.controlButton);
		Params p=(Params) getIntent().getSerializableExtra("params");
		
		name.setText(p.getName());
		note.setText(p.getNote());
		id=p.getId();
		
		controlButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				controlButton.setChecked(isChecked);
				if(isChecked){
					Toast.makeText(
							getApplicationContext(),
							"开启"+id+"按钮成功",
							Toast.LENGTH_SHORT).show();
				}else{
					Toast.makeText(
							getApplicationContext(),
							"关闭"+id+"按钮成功",
							Toast.LENGTH_SHORT).show();
				}
			}
		});


	}

}
第一个界面的单击事件
@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				  Intent intent = new Intent(MainActivity.this,SecondActivity.class);
                  //intent.setClass(ListViewActivity.this, ListActivity.class);
				  intent.putExtra("params", list.get(arg2));  
                  startActivity(intent);
                  System.out.println("aaa");

			}


第二个页面的xml      activity_second.xml

<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"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >
    </LinearLayout>

    <TextView
        android:id="@+id/itemNameValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:layout_marginTop="15dp"
        android:layout_toRightOf="@+id/linearLayout1"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/itemNoteValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/itemNameValue"
        android:layout_below="@+id/itemNameValue"
        android:layout_marginTop="77dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ToggleButton
        android:id="@+id/controlButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/itemNoteValue"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="76dp"
        android:text="ToggleButton" />

</RelativeLayout>



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值