package exam.RelativeTest;
import java.util.ArrayList;
import java.util.StringTokenizer;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
public class RelativeTestActivity extends Activity {
 
 String[] textArray ={"aa bb ccc dddddd eeeeee fffffff\n" +
      "gggggg hhhhhh iiiiiiiiii jjjjjjjjjjj kkkkkkkkkkk\n" +
      "lllllllllllllll mm nn oooooooo\n" +
      "ppppppppp qqqqqqqqq rrrrrrrrrrrr sssss\n" +
      "ttttt uuuuu vvvvv\n" +
      "ww xx yy\n" +
      "zzzz aa bbbbbbbbbbbbbbbbb c ddddddddddddddddd eeeeeeeeeee\n" +
      "fff gg hhhh iiiii jjjjjjjjjjj kkkkkkkkkkkk llllllllllll\n"
      };
 
 
 private StringTokenizer st;
 private String splitText;
 ArrayList<String> splitTextArr = new ArrayList<String>();
 ArrayList<String> splitTextArr2 = new ArrayList<String>();
 private String splitTextAll;
 private StringTokenizer st2;
 
 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        
        LinearLayout mainLayout = (LinearLayout)findViewById(R.id.ll);
        // 한문장
        st  = new StringTokenizer(textArray[0] , "\n");
        while (st.hasMoreTokens()) 
        {
         splitText = st.nextToken().trim();
         splitTextArr.add(splitText);
         
         LinearLayout listLayout = new LinearLayout(this);
         mainLayout.addView(listLayout);
         Log.e("문장",""+splitText);
        
         //단어
         st2  = new StringTokenizer(splitText , " ");
            while (st2.hasMoreTokens()) 
            {
             
             splitTextAll = st2.nextToken().trim();
             splitTextArr2.add(splitTextAll);
             Log.e("단어",""+splitTextAll);
             
//             final TextView tv = new TextView(this);   //기본 텍스트  뷰
//             tv.setText(splitTextAll);  //set
             
             StringView sv = new StringView(this,splitTextAll);   // 커스텀뷰
             listLayout.addView(sv);    //add
            }
            
            Log.e("NEW-LINe","=================================================");    
        }
        
    }
    public class StringView extends View {
  private Paint textPaint;
  private String str2;
  public StringView(Context context) {
   super(context);
   // TODO Auto-generated constructor stub
  }
  
  public StringView(Context context , String str) {
   super(context);
   Log.e("",str);
   str2 = str;
   // TODO Auto-generated constructor stub
  }
  public void onDraw(Canvas canvas)
     {
   Log.e("onDraw",""+str2);
      textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
         textPaint.setTextSize(30f);
         textPaint.setTypeface(Typeface.DEFAULT_BOLD);
         textPaint.setColor(Color.RED);
         canvas.drawText(str2, 0, 20, textPaint);
         super.onDraw(canvas);
     }
 }
    
}

 

 

소스는 위와 같구요..

 

테스트 프로젝트 만드셔서.소스 붙여넣으셔도 아마 그냥 될거같은데요.

테스트용으로 간단하게 이너클래스로 적용했구요...

 

 

 

문제 요지는.while 문 안에..반복문임에도 불굼하고 . 커스텀뷰가 한번만 호출되고..

그 한번 또한 반복문 도는 중에는.호출되지 아니하고...반복문이 끝난시점..

 

즉. 소스상 로그보시면..Log.e( NEW LINE========== 이라고 되있는부분) 있을겁니다..- 이부분이 두번재 while 문이 끝난시점인데요

 

거기에서 한번만...젤 첫번째 데이터만 한번 호출하고.끝나네요...

 

반복문에서..커스텀뷰.원래 호출안되나요?ㅡㅡ;; 말이 이상하네.;;

 

아효.ㅠㅠ

1111.png

 

젤아래 onDraw ..이 부분입니다

이렇게 한번만 타고 끝이나네요..ㅠㅠ~