마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

onClick 안에 저장된 값 밖에서 쓰기 질문용

0 추천
public void onLocationChanged(Location location) {
   
   

   position = (EditText)findViewById(R.id.position); 
   
   
   
   posiSave = (Button)findViewById(R.id.posiSave);
   
   
   
 posiSave.setOnClickListener(new OnClickListener() {
  
  @Override
  public void onClick(View v) {
   
   String inPutText = position.getText().toString();
   
  }
 });
   
   
   
   count++;

   StringBuffer buffer = new StringBuffer();

   /*buffer.append("수신횟수:"+count+"\r\n");*/

   buffer.append(inPutText + " 값:"+location.getLatitude()+"\r\n");

   buffer.append(inPutText + " 값:"+location.getLongitude()+"\r\n");

   
   //위치정보 출력하기

   result.setText(buffer.toString());
   
  }

 }; 

Sting inPutText 값을 밖에서 쓸려니까 안써져요 ㅠㅠ

onClick 나와서 바로 그값을 출력하고 싶은데 buffer.append(inPutText + "값: " + location.getLatitude();"/r/n");

이렇게 해스 inPutText 값을 보이고 싶은데 어떻게 하즈엉 ㅠ???

 

JOBG (610 포인트) 님이 2015년 3월 31일 질문
JOBG님이 2015년 3월 31일 수정

1개의 답변

+1 추천
 
채택된 답변
함수를 하나 만들어서 값을 넘기시든지

private void appendToBuffer(String input) {

    buffer.append(input + "값: "  + ...

}

 

buffer 를 멤버 변수로 참조해서 onClick 에서 처리하시든지

onClick(View v) {

    String inpuText = position.getText().toString();

    buffer.append(input + "값: " + ...

}

 

buffer 가 있는거보니 채팅 프로그램 같은거 하시는 모양인데

함수로 따로 빼서 append 하시기 전에 null checking, validation 하시구요
mamondebaltob (32,750 포인트) 님이 2015년 3월 31일 답변
JOBG님이 2015년 3월 31일 채택됨
잘안되서 그런데 전체 코드 올려놓았는데 한번만 봐주시겠습니까 ??ㅠㅠ
StringBuffer buffer = new StringBuffer();
 
   /*buffer.append("수신횟수:"+count+"\r\n");*/
 
   buffer.append(inPutText + " 값:"+location.getLatitude()+"\r\n");
 
   buffer.append(inPutText + " 값:"+location.getLongitude()+"\r\n");
 
    
   //위치정보 출력하기
 
   result.setText(buffer.toString());

이거를 onclick 안에다가 넣으세요
넣으니
buffer.append(inPutText + " 값:"+location.getLongitude()+"\r\n"); 에서 location 에러가 뜹니다 ㅠㅠ
인자로 받는 Location location 에다가 final 을 붙이세요
public void onLocationChanged(final Location location)
감사합니다. 완벽한 형태는 아니지만 구현은 됬습니다 ㅠㅠ 진짜 따봉 감사요 ㅋㅋ!!
...