2012-04-12 4 views
7
में editText.addTextChangedListener कैसे जोड़ें

मेरे काम के माहौल ग्रहण heliose, एंड्रॉयड 1.6TableLayout

मैं स्तंभों और पंक्तियों के साथ एक tableLayout बनाया है सफलतापूर्वक जोड़ दिया गया है, प्रत्येक कोशिका एक TextView है और एक EditText और मैं में एक समस्या है प्रत्येक सेल तक पहुंचने और सेल के अंदर प्रत्येक संपादन टेक्स्ट में addTextChangedListener जोड़ने की आवश्यकता है। इसलिए मुझे पाठ को इंगित करने के लिए अंग्रेजी पाठ को बदलने की आवश्यकता है। कृपया एक समाधान का सुझाव दें

/** 
* Here we are going to define the grid The Grid has 1. grid's value in the 
* particular position 2. 
*/ 

public void setGrid() { 

    String questionNumber[] = null; 

    Typeface fontface = Typeface.createFromAsset(getAssets(), "fonts/padmaa.ttf"); 
    /* 
    * Table layout for the crossword elements 
    */ 
    TableLayout tableLayout = (TableLayout) findViewById(R.id.crosswordTableLayout); 
    tableLayout.setGravity(Gravity.TOP); 
    tableLayout.setBackgroundColor(Color.WHITE); 
    tableLayout.setScrollContainer(true); 

    for (int i = 0; i < sizeOfGrid; i++) { 
     /* 
     * This table row params is used to set the layout params alone we 
     * are not going to use this anywhere 
     */ 
     TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     tableRowParams.setMargins(1, 1, 1, 1); 
     tableRowParams.height = 30; 
     tableRowParams.gravity = Gravity.TOP; 

     /* 
     * Defining the row element for the crossword 
     */ 
     TableRow tableRow = new TableRow(this); 
     tableRow.setBackgroundColor(Color.WHITE); 
     tableRow.setPadding(1, 0, 0, 0); 
     tableRow.setGravity(Gravity.TOP); 
     tableRow.setLayoutParams(tableRowParams); 

     for (int j = 0; j < sizeOfGrid; j++) { 

      /* 
      * (1).Here we are defining headerTextView to set the clue 
      * numbers. 
      * 2).columnEditText = a edit text view used to get the user 
      * i/p data 
      */ 
      TextView headerTextView = new TextView(this); 
      columnEditText = new EditText(this); 

      headerTextView.setGravity(Gravity.TOP); 
      headerTextView.setTextSize(10); 
      headerTextView.setEnabled(false); 
      headerTextView.setHeight(30); 
      headerTextView.setWidth(10); 
      headerTextView.setTextColor(Color.BLACK); 

      /* Override the edittext that has been created */ 
      columnEditText = (EditText) getLayoutInflater().inflate(R.layout.tablexml, null); 
      columnEditText.setHeight(30); 
      columnEditText.setWidth(25); 
      /* 
      * LinearLayout to arrange the two text view in a vertical 
      * position 
      */ 
      LinearLayout headerLinearLayout = new LinearLayout(tableRow.getContext()); 
      headerLinearLayout.setOrientation(LinearLayout.VERTICAL); 
      headerLinearLayout.addView(headerTextView); 

      /* 
      * LinearLayout to arrange the first Linearlayout and Edit text 
      * in a horizontal position 
      */ 
      LinearLayout cellLinearLayout = new LinearLayout(tableRow.getContext()); 
      cellLinearLayout.setOrientation(LinearLayout.HORIZONTAL); 
      cellLinearLayout.addView(headerLinearLayout); 
      cellLinearLayout.addView(columnEditText); 
      /* 
      * Here we are setting the table's vertical border by some 
      * workaround methods 
      */ 
      cellLinearLayout.setLayoutParams(tableRowParams); 
      /* 
      * the column with complete black 
      */ 
      if (cellValueArr[i][j] == null) { 
       columnEditText.setBackgroundColor(Color.BLACK); 
       headerTextView.setBackgroundColor(Color.BLACK); 
       headerTextView.setGravity(Gravity.TOP); 
       tableRow.setBackgroundColor(Color.BLACK); 
       columnEditText.setEnabled(false); 
      } else { 
       /* 
       * column with values and question numbers 
       */ 
       tableRow.setBackgroundColor(Color.BLACK); 
       if (quesNumArr[i][j] == null) { 
        columnEditText.setBackgroundColor(Color.WHITE); 
        headerTextView.setBackgroundColor(Color.WHITE); 
       } else if (quesNumArr[i][j] != null) { 
        /* 
        * column without question number 
        */ 
        questionNumber = quesNumArr[i][j].split("~"); 
        quesArrList.add(questionNumber[1]); 
        headerTextView.setText(questionNumber[1]); 
        headerTextView.setTextColor(Color.BLACK); 
        headerTextView.setBackgroundColor(Color.WHITE); 
        columnEditText.setBackgroundColor(Color.WHITE); 
       } 

      } 
      columnEditText.setId(i); 
      headerTextView.setId(i); 

      /* add the linear layout to the row values */ 
      tableRow.addView(cellLinearLayout); 

      int childCount = tableRow.getChildCount(); 
      System.out.println("Child Count ::" + childCount); 

      LinearLayout linearChild = (LinearLayout) tableRow.getChildAt(columnEditText.getId()); 
      colText = (EditText) linearChild.getChildAt(1); 
      System.out.println("GET ID " + linearChild.getChildAt(1).getId()); 

      colText.addTextChangedListener(new TextWatcher() { 
       @Override 
       public void onTextChanged(CharSequence seq, int start, int before, int count) { 
        // TODO Auto-generated method stub 
        if (seq.length() > 0 & before == 0) { 
         final String charSequence = String.valueOf(seq); 
         final String engChar = String.valueOf(seq.charAt(seq.length() - 1)); 
         println("GUJ :: currentlatin ===> " + engChar + " :: charSequence ==>" + seq); 
         // Method For Type Char 
         List softList = conv.getSoftKeyPressForChar(engChar, getApplicationContext(), seq); 
         charSeq = (String) softList.get(0); 
         Typeface fontface1 = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/padmaa.ttf"); 
         colText.setTypeface(fontface1, Typeface.NORMAL); 
         colText.setText(charSeq); 
         // for placing the cursor position 
         colText.clearFocus(); 
         colText.requestFocus(); 

        } 
       } 

       @Override 
       public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
        // TODO Auto-generated method stub 

       } 

       @Override 
       public void afterTextChanged(Editable s) { 
        // TODO Auto-generated method stub 
        System.out.println("AFTER TEXT CHANGE"); 
       } 
      }); 

     } 
     /* add the row values to the table layout */ 
     tableLayout.addView(tableRow); 
    } 
} 
+0

आप प्रोग्रामिंग क्यों कर रहे हैं? इसके बजाय आप सूची दृश्य के लिए एक कस्टम एडाप्टर बना सकते हैं जिसमें प्रत्येक आइटम के लिए 1 संपादन और टेक्स्टव्यू हो, यह डिजाइन और विकास दोनों भाग में आसान होगा। –

+0

उत्तर के लिए धन्यवाद, असल में हम एक क्रॉसवर्ड ऐप बना रहे हैं, इसलिए मैं ऐसा कर रहा हूं। यह क्रॉसवर्ड का फ़ॉन्ट इनर चरित्र है। इसलिए उपयोगकर्ताओं के इनपुट पर टेक्स्ट बदलने की जरूरत है। इसकी एक तरह का लिप्यंतरण यहां शामिल है। –

+0

इसका मतलब है कि आपके पास पंक्तियां * कोल्स स्क्रीन हैं, उदाहरण के लिए 4 * 4 –

उत्तर

0

मैंने पूरी तरह से कोड को नहीं देखा है। लेकिन मेरी प्रारंभिक समझ से, आप इसे इन तरीकों में से किसी में कर सकते हैं,

  1. पहले उल्लेख किया है किसी के रूप में, एक gridview के लिए जाते हैं। मैं उस मुद्दे पर अंतिम टिप्पणी से उस मुद्दे को अधिक नहीं कर सका, लेकिन अगर इसकी कुछ स्क्रॉल समस्या है, तो आप कुछ 5 डीपी के लिए लेआउट-मार्जिन-तल की कोशिश कर सकते थे, ताकि यह फसल न हो (अगर वह आपका क्या मतलब था)

  2. टेबल लेआउट के साथ जारी रखना, टेक्स्टवॉचर() को एक बार बनाएं और इसे लूप में अनुक्रमिक रूप से जोड़ें। यह अच्छा हो सकता है, अगर आप प्रत्येक तत्व के लिए आईडी सेट कर सकते हैं, या सेटटैग कर सकते हैं, तो पहले संपादन टेक्स्ट को नाम, "editText1", फिर, "editText2" मिलता है, आदि। तो एक लूप में, आप लूप इंडेक्स के आधार पर प्रत्येक तत्व का उपयोग कर सकते हैं।

संबंधित मुद्दे