Ventrix’s Code Folds

Author Archive

Android URLConnection ReadUTF

by ventrix on May.08, 2010, under android

URLConnection conn;
DataInputStream dis = null;
String url = “http://test.com/lalala.html”;
StringBuffer sb1 = new StringBuffer();
try {
URL updateURL = new URL(url);
conn = updateURL.openConnection();

BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), “UTF8″));

String s = “”;
while ((s = rd.readLine()) != null) {
sb1.append(s);
}
Log.i(”AAAAA”, sb1.toString());

Leave a Comment more...

Vertical AND Horizontal scroll on android

by ventrix on May.08, 2010, under android

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

<ScrollView android:id=”@+id/ScrollView01″
android:layout_width=”wrap_content” android:layout_height=”wrap_content”>
<HorizontalScrollView android:layout_width=”wrap_content” android:layout_height=”wrap_content”>

<ImageView android:id=”@+id/ImageView01″
android:layout_width=”fill_parent” android:layout_height=”fill_parent”></ImageView>

</HorizontalScrollView>

</ScrollView>

</LinearLayout>

1 Comment more...

Button up, listview in the middle, button bottom

by ventrix on May.08, 2010, under android

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

<TextView
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“You textview”
/>

<ListView
android:id=“@android:id/list”
android:layout_width=“fill_parent”
android:layout_weight=“1″
android:layout_height=“wrap_content” />

<TextView
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:layout_gravity=“bottom”
android:text=“Another textview but now beneath the ListView”
/>

</LinearLayout>

Leave a Comment more...

How to sort an ArrayList in Java

by ventrix on Sep.22, 2009, under android, java

Example:

Class Test {

public String name;

public String sirName;

}

ArrayList<Test> res = new ArrayList<Test>();

res.add(…);

res.add(…);

Comparator<Test> comperator = new Comparator<Test>() {

@Override
public int compare(Test object1, Test object2) {
return object1.name.compareToIgnoreCase(object2.name);
}

};
Collections.sort(res, comperator);

the list is now sorted by name.

:)

1 Comment more...

Android Keep Screen on

by ventrix on Sep.20, 2009, under android

You do not need the PowerManager.

Just call: View.setKeepScreenOn

http://developer.android.com/reference/android/view/View.html#setKeepScreenOn(boolean)

Leave a Comment more...

Android ListView Autoscroll

by ventrix on May.12, 2009, under android

If you are adding items in a listview and you want to autoscroll down, then you should call the

getListView().setSelection(NumberOfItems);

Leave a Comment more...


php string contains

by ventrix on Feb.12, 2009, under Uncategorized

$text = “this is a happy cow”;
$a = “happy”;

if (strlen(strstr($text,$a))>0) {
echo “contained”;
} else {
echo “not contained”;
}

Leave a Comment more...

Read all the raw data posted in a php script

by ventrix on Feb.04, 2009, under php

Read all the raw data posted in a php script

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   $str = trim(file_get_contents('php://input'));
}
Leave a Comment : more...

Java socket timeout

by ventrix on Jan.30, 2009, under android, j2ee, j2me, j2se, java

private String socketIP="192.168.1.1";
private int socketPort=2424;
private int timeout=5000; //5 seconds

Socket socket1 = new Socket();
socket1.connect(new InetSocketAddress(this.socketIP, this.socketPort), timeout);
//or else
Socket socket1 = new Socket();
socket1.connect(new InetSocketAddress(this.socketIP, this.socketPort));
socket1.setSoTimeout(timeout);

http://java.sun.com/j2se/1.4.2/docs/api/java/net/Socket.html

Leave a Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...