반응형



안드로이드에서 버튼을 눌르고 있을때 이벤트 주기 


        button_03.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

int action = event.getAction();

if(MotionEvent.ACTION_DOWN == action){

onHandlerUp();

}else if(MotionEvent.ACTION_UP == action){

mHandler.removeCallbacks(r);

}

return true;

// TODO Auto-generated method stub

// return false;

}

});



    private Runnable r;

    private void onHandlerUp() {

mHandler = new Handler();

r = new Runnable() {

@Override

public void run() {

tc = new TCP_Client();

 

 myTaskParams = "2";

 

     tc.execute(myTaskParams);

mHandler.postDelayed(r, 100);

}

};

mHandler.postDelayed(r, 20);

}




메인 스레드                       서브 스레드

UI  관런 변경         <===>    작업수행 


안드로이드는 메인 스레드 (백그라운드에서 ui) 변경시키면 에러 발생 

서로 변경 하는것을 허용하게 되면 동기화 문제 발생     

핸들러를 이용하여 스레드간에 통신 할수 있도록 함.



postDelayed(mRunnable, 1000); // mRunnable 객체를 1초 뒤에 실행



반응형

'programming' 카테고리의 다른 글

델파이 포인터 예제  (0) 2020.03.26
소캣 함수  (0) 2014.12.23
TCP 소켓의 기초  (0) 2014.12.23
Socket accept()호출 Invalid 에러  (0) 2014.12.18
반응형

리스트 뷰(listView) 어댑터 뷰(AdapterView)중에 가장 많이 사용된다


 여러개의 항목을

수직으로 펼쳐서 보여주는 기능을 한다


ArrayAdapter(현재 액티비티,레이아웃 리소스 ID ,List<T> objects)

ArrayAdapter(Context context,ini textViewResourceld,List<T> objects)
ArrayAdapter(Context context,ini textViewResourceld,T[] objects)

                                    
 레이아웃 리소스 ID
 Simple_list_item_1
 Simple_list_item_2 
 Simple_list_item_checked
 simple_list_item_single_choice
 simple_list_item_multiple_choice



작성중[...] 


반응형
반응형


반응형
반응형

 


  ImageView topview =(ImageView)this.findViewById(R.id.Todo_top_img);
        TextView inText =(TextView)this.findViewById(R.id.in_text);







  ImageView topview =(ImageView)this.findViewById(R.id.Todo_top_img);
        TextView inText =(TextView)this.findViewById(R.id.in_text);
 inText.setMaxHeight(20);   //  ImageView 최대크기 설정






반응형
반응형
package test.test;

import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.view.*;

public class mainA extends View {
   
    private static Bitmap mainimg;
   
    private static Bitmap newg;
    private static Bitmap cont;
    private static Bitmap lan;
    private static Bitmap qit;
   
   
    public mainA(Context context) {
        super(context);
        setBackgroundColor(Color.WHITE);
       
        Resources r= context.getResources();
        //image =BitmapFactory.decodeResource(r,R.drawable.a);
       
        mainimg =BitmapFactory.decodeResource(r,R.drawable.mainimgpng);
       
        newg =BitmapFactory.decodeResource(r,R.drawable.newgame);
        cont =BitmapFactory.decodeResource(r,R.drawable.cont);
        lan =BitmapFactory.decodeResource(r,R.drawable.lan);
        qit =BitmapFactory.decodeResource(r,R.drawable.quit);
       
       
       
       
       
       
        // TODO Auto-generated constructor stub
    }

   
    Paint p=new Paint();
   
   
    protected void onDraw(Canvas canvas) {
        int w= mainimg.getWidth();
        int h=mainimg.getHeight();
   
       
        Rect src =new Rect(0,0,w,h);
        Rect dst =new Rect(0,0,getWidth(),getHeight());
       
               
        canvas.drawBitmap(mainimg, src,dst, null);
       
        ///////////////////
       
    /*    int newgw= newg.getWidth();
        int newgh=newg.getHeight();
        Rect newgsrc =new Rect(0,0,w,h);
        Rect newgdst =new Rect(0,0,getWidth(),getHeight());*/
        /*Rect gnesrc =new Rect(0,0,0,0);
        Rect gnewdst =new Rect(0,0,0,0);*/
        //canvas.drawBitmap(newg, gnesrc,gnewdst, null);
        /*       
         *
         */
        int statgw=(getWidth()/2)+(getWidth()/5);
       
        int statgh=(getHeight()/2)-(getHeight()/2);
        canvas.drawBitmap(newg,statgw,statgh, null);
        canvas.drawBitmap(cont,statgw,statgh+60, null);
        canvas.drawBitmap(lan,statgw,statgh+120, null);
        canvas.drawBitmap(qit,statgw,statgh+180, null);
       
       
       
        // TODO Auto-generated method stub
        super.onDraw(canvas);
    }

}




반응형

+ Recent posts