Sunday, November 9, 2008

EditText with limited number of characters

I just fough with the SDK for quite some time to find this one.

As a average modern programer, I started by looking on the internet, but didn't find anything. I imagine I didn't search the right sites ( no comments on this please ! )

So this is what I came up with :


editEntryView.setOnKeyListener
(
new View.OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
EditText NameView = (EditText ) editEntryView.findViewById( R.id.PlayerName );
String Name = NameView.getText().toString();
if ( Name.length() >= 8 )
{
if ( keyCode != KeyEvent.KEYCODE_DEL )
return true;
}
return false;
}
}
);

I imagine that there are many things that should be cleaner here, but, hey !, it works, and that so good for me !

I fought for some time, because I was looking for a way to call a parent method when I didn't treat the case and decided to pass for this letter.
Actually, the behaviour is just the opposite :
if you return true, it means you dealed with the entry, so the treatment will stop here.
if you return false, it means you didn't deal with the entry, so it will be passed to the next listener.

Actually, a classic listener pattern !



Next thing : enter as a ok-click entry !

Saturday, November 8, 2008

List with custom or no separator

My achievement today ( OK, it's just a small one )

I wanted to have no separator in my list activity...

After some moment parsing all the documentation in every possible way, here what I found :

public class ScorePage extends ListActivity
{

Score mScore;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);

this.getListView().setDivider( null );
this.getListView().setDividerHeight(0);
}


By the way, is the DividerHeight set necessary ?
I added it because of a very stressful comment on the SetDivider method...

(One test later )

It is by no way necessary !!
But I find that adding a non zero height was what I was wanting for, ie adding a blank space between two entries !


Next step tomorrow !

Starting point

This is the first message...

As usual ( ? ), it doesn't have any purpose, but essentially to verify that the text I'm writing right now will appear somewhere on the Internet !

So I will just introduce myself :
I'm a (professional) game developer, so quite an expert of C++ trickery, essentially on Xbox360 and PS3 ( though I also worked on Wii, PS2 and GC ), and, obviously, on PC.

This is the diary of the creation, in my spare time ( essentially my nights, when wife and kids are sleeping ), of a casual game on Google Android phones !

I'm discovering java, the mobile world, eclipse, and the Google world !