implements OnClickListener问题 10
=============MainActivity.java==========publicvoidonClick(Viewv){intid=v.getId();Inte...
=============MainActivity.java==========
public void onClick(View v)
{
int id = v.getId();
Intent intent = new Intent();
intent.setClass(MainActivity.this, LayerTwo.class);
Bundle bundle = new Bundle();
switch(id)
{
case R.id.btnA:
bundle.putString("Classs","A");
intent.putExtras(bundle);
startActivity(intent);
break;
case R.id.btnB:
bundle.putString("Classs","B");
intent.putExtras(bundle);
startActivity(intent);
break;
}
}
}
============LayerTwo.java============
public class LayerTwo extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layertwo);
Bundle bundle = this.getIntent().getExtras();
String Classs = bundle.getString("Classs");
//String Classs = "A";
TextView textView1=(TextView) findViewById(R.id.textView1);
textView1.setText(Classs);
}
}
调试了半天,编译通过了,但是一直不能跳转到第二个界面 展开
public void onClick(View v)
{
int id = v.getId();
Intent intent = new Intent();
intent.setClass(MainActivity.this, LayerTwo.class);
Bundle bundle = new Bundle();
switch(id)
{
case R.id.btnA:
bundle.putString("Classs","A");
intent.putExtras(bundle);
startActivity(intent);
break;
case R.id.btnB:
bundle.putString("Classs","B");
intent.putExtras(bundle);
startActivity(intent);
break;
}
}
}
============LayerTwo.java============
public class LayerTwo extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layertwo);
Bundle bundle = this.getIntent().getExtras();
String Classs = bundle.getString("Classs");
//String Classs = "A";
TextView textView1=(TextView) findViewById(R.id.textView1);
textView1.setText(Classs);
}
}
调试了半天,编译通过了,但是一直不能跳转到第二个界面 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询