Wednesday, August 13, 2014

ANDROID Frame Layout - ImageView Change Example

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   <ImageView
      android:id="@+id/imageView1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:scaleType="center"
      android:src="@drawable/android3d"
      android:contentDescription="@string/Message"/>
   <Button
      android:id="@+id/btnChangeImage"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:padding="10dp" 
      android:background="#000"
      android:textColor="#fff"
      android:text="@string/ButtonMessage"/>

</FrameLayout>


package com.nkaya.test;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

   Button button;
   ImageView image;
   /**Called when the activity is first created.*/
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      addListenerOnButton();
   }

   private void addListenerOnButton() {
      image=(ImageView) findViewById(R.id.imageView1);
      button=(Button) findViewById(R.id.btnChangeImage);
      button.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
            image.setImageResource(R.drawable.android);
         }
      });
   }
}


Saturday, August 9, 2014

ANDROID Table Layout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:shrinkColumns="0"
 android:stretchColumns="1">
 <TableRow >
   <TextView
      android:text="@string/Red"
      android:background="#cc0000"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
   <TextView
      android:text="@string/Green"
      android:background="#00cc00"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
   <TextView
      android:text="@string/Blue"
      android:background="#0000aa"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
 </TableRow>
 <TableRow >
   <TextView
      android:text="@string/Blue"
      android:background="#0E0EED"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
   <TextView
      android:text="@string/Yellow"
      android:background="#FCFC05"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
 </TableRow>

</TableLayout>


ANDROID Linear Layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal"
 tools:context="com.example.adsoyad.MainActivity" >
 <TextView
   android:text="@string/Red"
   android:background="#aa0000"
   android:layout_width="wrap_content"
   android:layout_height="match_parent"
   android:layout_weight=".33" />
 <TextView
   android:text="@string/Green"
   android:background="#00aa00"
   android:layout_width="wrap_content"
   android:layout_height="match_parent"
   android:layout_weight=".33" />
 <TextView
   android:text="@string/Blue"
   android:background="#0000aa"
   android:layout_width="wrap_content"
   android:layout_height="match_parent"
   android:layout_weight=".33" />
</LinearLayout>


Monday, August 4, 2014

PL/SQL How to Return Object Value with PL/SQL Function

--create obj type
   create type          "obj_user_bank_account"                                          as
    object (
            user_id               number(18)  ,
            account_number                varchar2(50),
            bank_name               varchar2(50)
           );

--create pkg spec
    function fnc_user_bank_account_no(p_user_id in number) return obj_user_bank_account;

--create pkg body
    function fnc_user_bank_account_no(p_user_id in number) return obj_user_bank_account is
      objuseraccountbank obj_user_bank_account  :=  obj_user_bank_account (null, null, null);
      accountno                                         table_user_bank_accounts.account_number%type;
      bankname                                        table_banks.adi%type;  
    begin
      select  count(*)
        into  rowcnt
        from  table_user_bank_accounts account
       where  account.user_id = p_user_id
         and  default=1;
   
      if rowcnt >0 then
        select  account.account_number, bank.adi
          into  accountno, bankname
          from  table_user_bank_accounts account,
                table_banks bank
         where  account.user_id=p_user_id
           and  account.bank_id=bank.id
           and  account.default=1;
       
        objuseraccountbank.user_id := p_user_id;
        objuseraccountbank.account_number  := accountno;
        objuseraccountbank.bank_name := bankname;
     
        return objuseraccountbank;
      else
        select  account_number, adi
          into  accountno, bankname
          from( select  account.account_number,
                        bank.adi
                  from  table_user_bank_accounts account,
                        table_banks bank
                 where  account.user_id = p_user_id
                   and  account.bank_id  = bank.id
              order by  account.id desc)
         where  rownum=1;

        objuseraccountbank.user_id := p_user_id;
        objuseraccountbank.account_number  := accountno;
        objuseraccountbank.bank_name := bankname;
     
        return objuseraccountbank;
      end if;
    end;

--create view
    create or replace view test_view
    as
      (select pkg_ort.fnc_user_bank_account_no(knt.id).account_number_no from dual) account_number,
      (select pkg_ort.fnc_user_bank_account_no(knt.id). bank_name from dual)  bank_name
    from table_users knt
    order by knt.id;

PL/SQL Retrieving Max Value + Corresponding Another Column Value

   select *
         from( select b.id,
                            b.account_no,
                            max(b.id) over() mx
                 from table_bank b
                where b.user_id=p_user_id
                  and b.default=1
              ) hes
        where hes.id = hes.mx ;
     

Tuesday, July 15, 2014

PL/SQL START WITH & LEVEL & SIBLINGS

select  b.id,
        b.root_id,
        lpad ( ' ', 5 * ((decode(level,1,0,level))) ) || b.name dept_name,
        decode(b.active ,1,'X',' ') active
from schema_name.table_name b
connect by prior b.id=b.root_id
start with b.id=:p_id
order siblings by b.name;

Monday, July 14, 2014

PL/SQL GROUP BY inside a SUBQUERY

select   d.dname ,
           t.job,
           t.cnt
 from   dept d,
          (select  deptno,
                      job,
                      count(empno) cnt
             from  emp
      group by  deptno,job ) t
where  t.deptno = d.deptno;