Android 如何根据活动中的更改更改textview
我是android开发的新手。我正在做一个有10个问题(10个活动)的测验。还有另一个活动(名称“Lost”),该活动在回答错误时打开,并根据问题编号(活动编号)包含一个文本视图(告诉到目前为止的分数)。我无法根据活动编号设置文本视图。例如,如果一个人在第5次提问时失败,活动(丢失)将打开并将textview设置为50,而当他在第9次提问时给出错误答案时,活动(丢失)将打开并将textview设置为90。我不知道怎么做。。帮帮我 这是我的密码- 这是第一个问题(类似的代码用于其他问题)- 这是“丢失”活动代码Android 如何根据活动中的更改更改textview,android,android-activity,Android,Android Activity,我是android开发的新手。我正在做一个有10个问题(10个活动)的测验。还有另一个活动(名称“Lost”),该活动在回答错误时打开,并根据问题编号(活动编号)包含一个文本视图(告诉到目前为止的分数)。我无法根据活动编号设置文本视图。例如,如果一个人在第5次提问时失败,活动(丢失)将打开并将textview设置为50,而当他在第9次提问时给出错误答案时,活动(丢失)将打开并将textview设置为90。我不知道怎么做。。帮帮我 这是我的密码- 这是第一个问题(类似的代码用于其他问题)- 这是“
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lost);
// Show the Up button in the action bar.
setupActionBar();
Button home=(Button)findViewById(R.id.Home);
home.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Intent myintent=new Intent(view.getContext(), MainActivityQuiz.class);
startActivityForResult(myintent,0);
}
});
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.lost, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
请告诉我如何做…在你的水平活动中,为你的意图添加一个额外的内容
Intent myintent=new Intent(view.getContext(), Lost.class);
myintent.putExtra("score", LEVEL_SCORE);
startActivityForResult(myintent,0);
其中,LEVEL_SCORE是与您的级别关联的整数分数。
在丢失活动中,您可以通过以下操作获得分数:
Intent myIntent = getIntent();
int score = myIntent.getIntExtra("score");
您现在可以在文本视图中显示分数。我应用了这个,但它只适用于一个级别(问题)。文本视图也必须根据其他问题进行更改。我是否应该使用一个开关盒,其排列方式会根据活动编号或名称进行更改?也许您可以在意图中传递更多信息。。。例如,您可以在已启动的活动中传递字符串并使用getStringExtra(),最终可以根据ReceiveID数据切换大小写以构建textview,然后您可以告诉我可以通过什么方法使用该切换,例如public void onCheckedChanged(RadioGroup arg0,int arg1)用于RadioGroup。什么是文本视图?
Intent myIntent = getIntent();
int score = myIntent.getIntExtra("score");