我得到了一个带有字符串的意图ia新活动,我想在TextView
内显示字符串,我试图在TextView
内声明我的onCreate
但它崩溃了。我如何才能显示变量"requestbuff"
?
public class RequestDetail extends MainActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
Intent intent = getIntent();
String requestbuff = intent.getExtras().getString("Requête");
TextView details = (TextView)findViewById(R.id.detailreq);
details.setText(requestbuff);
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_req);
}
}
答案 0 :(得分:0)
这样可以正常工作。将setContentView放在方法的开头,以便创建视图。之后,您可以使用findViewById()
public class RequestDetail extends MainActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_req);
Intent intent = getIntent();
String requestbuff = intent.getExtras().getString("Requête");
TextView details = (TextView)findViewById(R.id.detailreq);
details.setText(requestbuff);
}
}