Code snippets
satya - Friday, September 16, 2011 9:54:09 AM
responding to buttons
Somclass
implements View.OnClickListener
{
@Override
public void onClick(View v)
{
}
}//eof-class
satya - Friday, September 16, 2011 9:57:20 AM
further more
@Override
public void onClick(View v)
{
Button b = (Button)v;
if (b.getId() == R.id.plusButton)
{
}
}
satya - Friday, September 16, 2011 10:05:03 AM
I need this often
private boolean invalidString(String s)
{
return !validString(s);
}
private boolean validString(String s)
{
if (s == null)
{
return false;
}
if (s.trim().equalsIgnoreCase(""))
{
return false;
}
return true;
}
satya - Friday, September 16, 2011 10:52:47 AM
You can use this link to see the following sample code
You can use this link to see the following sample code
How to create a layout with
textviews
buttons
linear layout
vertical
horizontal
how to gather controls
how to setup buttons
how to respond to buttons
how to read/update edit text controls
satya - Thursday, September 29, 2011 5:51:49 PM
quickest way to start an activity
Intent i = new Intent(this,ThirdActivity.class);
startActivity(i);
satya - Friday, September 30, 2011 9:01:21 PM
Another example
private void gotoPlay(String wordRef)
{
Intent intent = new Intent(this.ctx,UnscrambleActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("neword", wordRef);
this.ctx.startActivity(intent);
}
satya - Saturday, October 01, 2011 11:21:07 AM
Brief meaning of these two flags
Go back to the activity in the history and make it the top of the stack by closing every one else above. Also dont' start a new one but invoke the onNewIntent() method on that activity.
satya - Monday, November 07, 2011 1:42:35 PM
Here is a way to set onClick for a button in xml
<Button
android:id="@+id/btn_st_animation"
...other stuff
android:onClick="startAnimationCB"
android:text="Start Animation" />
satya - Monday, November 07, 2011 1:43:26 PM
Here is the onClick signature
public void startAnimationCB(View someView)
{
Log.d(tag,"button clicked");
animateTv();
}
satya - Monday, November 07, 2011 1:44:17 PM
The following is wrong
public void startAnimationCB(Button someButtonView)
{
}