本文介绍了我如何使用意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我的应用程序需要两个活动。第一个活动中的一个按钮必须转到另一个活动。但是当我单击按钮时它显示不幸我的应用程序已停止。我使用了intents.where是问题。它基本上是一个文本到语音应用。

my app need two activity.a button in the first activity must take to the another activity.but when i click the button it shows unfortunately my app stopped.i used intents.where is the problem.it is basically a text to speech app.

MainActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.launcher);

	btnCtlr = (Button) findViewById(R.id.button1);
	btnCtlr.setOnClickListener(new ButtonClickHandler());
}

public class ButtonClickHandler implements View.OnClickListener {
	public void onClick(View view) {

		Intent intObj = new Intent(MainActivity.this, Welcome.class);

		startActivity(intObj);
	}
welcome.java
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	ed1 = (EditText) findViewById(R.id.editText);
	b1 = (Button) findViewById(R.id.button);

	t1 = new TextToSpeech(getApplicationContext(),
			new TextToSpeech.OnInitListener() {
				@Override
				public void onInit(int status) {
					if (status != TextToSpeech.ERROR) {
						t1.setLanguage(Locale.UK);
					}
				}
			});

	b1.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			String toSpeak = ed1.getText().toString();
			Toast.makeText(getApplicationContext(), toSpeak,
					Toast.LENGTH_SHORT).show();
			t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
		}
	});
}

public void onPause() {
	if (t1 != null) {
		t1.stop();
		t1.shutdown();
	}
	super.onPause();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.main, menu);
	return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
	// Handle action bar item clicks here. The action bar will
	// automatically handle clicks on the Home/Up button, so long
	// as you specify a parent activity in AndroidManifest.xml.

	int id = item.getItemId();

	// noinspection SimplifiableIfStatement
	if (id == R.id.action_settings) {
		return true;
	}
	return super.onOptionsItemSelected(item);
}

推荐答案


这篇关于我如何使用意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:31