[code language=”java”]
{
final InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source,
int start, int end, Spanned dest, int dstart,
int dend)
{
for (int i = start; i < end; i++)
{
if (Character.isDigit(source.charAt(i))||Character.isLetter(source.charAt(i)))
{
return "";
}
}
return null;
}
};
answerTXT.setFilters(new InputFilter[]{filter});
[/code]
Category: IT
ContextWrapper ContextImpl getBaseContext
ActivityThread casts Application.getBaseContext() to ContextImpl
[code language=”java”]
static ContextImpl getImpl(Context context) {
Context nextContext;
while ((context instanceof ContextWrapper) &&
(nextContext=((ContextWrapper)context).getBaseContext()) != null) {
context = nextContext;
}
return (ContextImpl)context;
}
[/code]
Potential crash when !(context instanceof Activity)
[code language=”java”]
public static Activity unwrap(Context context) {
while (!(context instanceof Activity)) {
ContextWrapper wrapper = (ContextWrapper) context;
context = wrapper.getBaseContext();
}
return context;
}
[/code]
SHS to RTF
How to compile java. How to build jar
Why did I decide to write this post?
Because of these:
[code language=”java”]
Could not find or load main class
[/code]
or How to specify main class for console app.
Start and kill process in Delphi
[code language=”pascal”]
var
PrIn: TProcessInformation;
StIn: TStartupInfo;
Res: bool;
ProcID, Process: Cardinal;
// start
begin
GetStartupInfo(StIn);
Res := CreateProcess(PChar(‘..\Project1.exe’),
PChar(‘"command line params"’), nil, nil, False, CREATE_NEW_PROCESS_GROUP,
nil, nil, StIn, PrIn);
ProcID := PrIn.hProcess;
Process := PrIn.dwProcessId;
end;
// kill
begin
TerminateProcess(ProcId, 0);
end;
[/code]