2012-12-02 3 views
2

문자열의 길이에 따라 gridView를 만들려고합니다. 내가 15는 containes의 tableview를 craeted - 나는 이전에 C#에서 비슷한 짓을했고 문자열에 공백이 없음을 가정 ...안드로이드의 gridView에 동적으로 textView를 추가합니다.

- 밑줄 -

모든 텍스트 뷰는 하나의 문자를 표시해야합니다 lables, 그리고 글자 수를 기준으로, 각각 오른쪽으로 옮겼습니다.

public void setLetters(String str) 
     { 
      tableLayoutPanel1.Visible = false; 
      int x = revah(str); //revah returns the number of letters in the string 
      int yy = x/2; 
      int count = 0; 
      if (count <= x) 
      { 
       tableLayoutPanel1.SetColumn(lbl0, yy); 
       count++; 
      } 
      if (count <= x) 
      { 
       tableLayoutPanel1.SetColumn(lbl1, yy); 
       count++; 
      } 
      if (count <= x) 
      { 
       tableLayoutPanel1.SetColumn(lbl2, yy); 
       count++; 
      } 
      if (count <= x) 
      { 
       tableLayoutPanel1.SetColumn(lbl3, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl4, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl5, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl6, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl7, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl8, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl9, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl10, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl11, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl12, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl13, yy); 
      count++; 
     } 
     if (count <= x) 
     { 
      tableLayoutPanel1.SetColumn(lbl14, yy); 
      count++; 
     } 

     tableLayoutPanel1.Visible = true; 

    } 

나는 방법도 ... 도움을 시작할 수있는 gridview를 사용하여 안드로이드에서 비슷한 일을 수행하고자하지만, 아무 생각이 ...

+0

textview 값이 helloworld 인 것처럼 halloworld를 gridview에 표시하려는 것보다 h l l l o w l r l d? 내가 뭘 했니? – Zohaib

+0

음 ... 정확하지는 않지만 ... 저에게 어떻게하는지 보여 주시면, 아프세요 : – omi

+0

코드를 더 간단하게 만들 수있는 방법이 보이지 않습니까? :) –

답변

1

이 다음과 같이하십시오. link 이것은 그리드보기를 만드는 방법을 보여줍니다. 당신은 textview 값을 읽고 그 단어를 단일 문자로 분리하고 문자열 []에 해당 문자를 추가하는 논리를 만드는 방법을 만들어야합니다. 이 도움이 되길 바란다

+0

great link ... 고맙습니다! – omi

1

당신은을 만들 수 있습니다 그것은 더 많거나 적은 같은 외모 GridView (Activity - http://developer.android.com/reference/android/app/Activity.html에 의해 비정상적으로 확장 됨) 및 다른 레이아웃이 텍스트 뷰와 함께 제공됩니다. 그런 다음 GridView (ArrayAdapter)에 문자열 (getView 메서드에)을 채우는 어댑터를 구현해야합니다. getCount() 메서드는 항목 수를 결정합니다. 이 메소드는 ArrayAdapter 클래스에 있으므로 무시해야합니다. 여기에서 확인하십시오 : http://developer.android.com/reference/android/widget/ArrayAdapter.html

+0

감사합니다 ... 정말로 arrayAdapter와 함께 작업하는 법을 배워야합니다 ... – omi

관련 문제