Thursday 12 September 2013

Android: Get the x and y values of a View.



@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
TextView tv = (TextView) findViewById(R.id.advancedSearch_text);
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.mfrags);
readLocation(mainLayout, tv);
}



private void readLocation(View mainview, View childView) {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int offsetX = displayMetrics.widthPixels - mainview.getMeasuredWidth();
int offsetY = displayMetrics.heightPixels
- mainview.getMeasuredHeight();
int[] locationInWindow = new int[2];
childView.getLocationInWindow(locationInWindow);
int[] locationOnScreen = new int[2];
childView.getLocationOnScreen(locationOnScreen);

System.out.println("vdjvhbjdhvbdjvhbdjvhbdjvh" +"getLocationInWindow() - " +          
                                   locationInWindow[0] + " : "
+ locationInWindow[1] + "getLocationOnScreen() - "
+ locationOnScreen[0] + " : " + locationOnScreen[1]
+ "Offset x: y - " + offsetX + " : " + offsetY);

}

Wednesday 11 September 2013

Android: get the MIME type from the URL


String name="image.png"
String nameType = URLConnection.guessContentTypeFromName(name);

Android: get the number of lines occupied by the textview dynamically.


@Override
public void run() {
    // TODO Auto-generated method stub
    while(textView.getLineCount() == 0){

    }
    countLine = textView.getLineCount(); 

}

Wednesday 4 September 2013

Android: Progress Image type loader using progress dialog


 <RelativeLayout
            android:id="@+id/loadingProgressLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ProgressBar
                style="?android:attr/indeterminateProgressStyle"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_centerInParent="true"
                android:layout_gravity="center"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:layout_toLeftOf="@+id/textId" />

            <TextView
                android:id="@+id/textId"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="Loading..."
                android:textAppearance="@android:style/TextAppearance.Medium"
                android:textColor="@android:color/black"
                android:visibility="visible" />
        </RelativeLayout>

Tuesday 3 September 2013

Android: get the Childs of ListView with ListViewId


for (int i = 0; i < listview.getChildCount(); i++) {
RadioButton radioCatOne = (RadioButton) listview.getChildAt(i).findViewById(R.id.radiobuttonId);
}