第二个页面的代码
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>