mytechead

Android & Wordpress Help center

Archive for the month “February, 2012”

How to toggle android emulator full screen mode.

Recently while coding for my android application i accidentally hit a key combination that made my emulator enter full screen mode. After trying the common key combinations to get out of full screen modes i ended up googling the solution as none of those key combinations worked.

After googling i found that in order to toggle emulator’s full screen mode we can use the key combination :

ALT + ENTER

Advertisements

Android debug keystore expired!!

Hello everyone….

Recently while working on android i came across a very subtle issue because of which i wansn’t able to compile my android program.

The error that i was getting said :

Error generating final archive: Debug certificate expired on 8/2/2012 2:35 PM!

and the solution to get rid of this error is :

Delete your debug certificate under ~/.android/debug.keystore on Linux and Mac OS X; the directory is something like %USERPROFILE%/.android on Windows.

Hope it helps everyone out there who may in near future face this problem!! 😉

Send POST data to WebView urls

In order to send POST data in the url being loaded inside a WebView, instead of using the loadUrl(“http://myurl.com”) method postUrl() method can be used.

Documentation :

public void postUrl (String url, byte[] postData)
Since: API Level 5

Load the url with postData using “POST” method into the WebView. If url is not a network url, it will be loaded with {link loadUrl(String) instead.
Parameters
url The url of the resource to load.
postData The data will be passed to “POST” request.

Code snippet :

WebView mWebView = (WebView) findViewById(R.id.mWebView); // WHERE R.id.mWebView is of course webview in your layout file.

mWebView.postUrl("http://myurl.com",
EncodingUtils.getBytes("param1=value1&param2=value2","BASE64"));

Here first param to the postUrl() method is ‘url’ to which we want to send the data & the second parameter is the POST data. Since second param is of type bytes we have used ‘getBytes’ method of EncodingUtils class to get bytes from our POST data.

Create iOS like clearTextButton in Android

Hey Guys… I just came across a scenario where i had to code to create an iOS like clearTextButton, so just thought sharing it up with you all.
So here it goes…

Features:

  • With this it’ll be possible to hide the clearTextButton when nothing has been typed.
  • When user types even a single character clearTextButton appears
  • When user clicks clearTextButton the contents of Text field is cleared and clearTextButton vanishes

Create a layoout file in your android layout folder and call name it lets say “clear_text_button_Demo.xml”

Now to create an iOS like clearTextButton we’ll be using a RelativeLayout, the reason why RelativeLayout will be used is we’ll be placing the clearTextButton on the EditText field. so as to give an impression that the clearTextButton is a part of EditText field. Something like this will be the output:

clearEditTextButtonDemo

clear_text_button_Demo.xml:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >

<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”46dp”
android:orientation=”horizontal” >

<EditText
android:id=”@+id/queryBox”
android:layout_width=”255dp”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_alignParentRight=”true”
android:layout_weight=”1.56″ android:singleLine=”true”/>

<ImageView
android:id=”@+id/clearButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentRight=”true”
android:layout_centerVertical=”true”
android:src=”@drawable/cross” android:layout_marginRight=”10dp” android:visibility=”false” />

</RelativeLayout>

</LinearLayout>

Now here id of our EditText is queryBox & id of our Image view is clearButton. Now we have to add handlers in our “activity” to clear the contents of EditText when clearButton is pressed.

Activity:

public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_clearable_edit_text);
clearTextListener();
}

private void clearTextListener() {

EditText searchEditText = (EditText) findViewById(R.id.query_box);

final ImageView clearButtonImage = (ImageView) findViewById(R.id.clearButton);

clearButtonImage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

searchEditText.setText(“”);
clearButtonImage.setVisibility(View.GONE);

}

});

searchEditText.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

if(s.length() 0){
clearButtonImage.setVisibility(View.VISIBLE);

}

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub

}
});

}
}

Post Navigation