Click here to Skip to main content
15,885,855 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi guys ,

Im new on Android App Development.

Its quite simple code in Android. When checkBox is checked , I will set text to textView control.

sendMessage method is launched with the button OnClick Method.


And also , how can i prevent "Android stopped launch" error ? And how can i show the error written in Code ?

Thans for your help




C#
package com.example.myandroid;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	Button btn = (Button)findViewById(R.id.button1);
	CheckBox cinsiyet = (CheckBox)findViewById(R.id.checkBox1);
	TextView text = (TextView)findViewById(R.id.textView1);
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	public void sendMessage(View v)
	{
	if(cinsiyet.isChecked()==true)	
		text.setText("Secili");
	else 
		text.setText("secili degil");
    

	}
}
Posted
Updated 10-Dec-13 5:10am
v2
Comments
Sergey Alexandrovich Kryukov 10-Dec-13 11:10am    
You did not explain the problem you face.
—SA
beratxt 10-Dec-13 11:20am    
threadid=1: thread exiting with uncaught exception (group=0x40c27a68)
Richard MacCutchan 10-Dec-13 11:21am    
You have three statements before your onCreate method. Are you sure they should be there and not inside some method?
Ganesh KP 10-Dec-13 23:49pm    
Try to move the controls initialization to onCreate() method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900