2012-08-31 2 views
0

мой вопрос в том, как поставить ScrollView HorizontalScrollView и таблицу с массивом TextView.добавить ScrollView и HorizontalScrollView в TableLayout

Это мой main.java:

public class tabla extends Activity { 

    SitesList sitesList = null; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_tabla); 

     TableLayout layout =(TableLayout)findViewById(R.id.tabla); 

     TableRow tr[] = new TableRow[80]; 

     TextView variacion[]; 
     TextView nemotecnico[]; 
     TextView precio[]; 

     try { 

      /** Handling XML */ 
      SAXParserFactory spf = SAXParserFactory.newInstance(); 
      SAXParser sp = spf.newSAXParser(); 
      XMLReader xr = sp.getXMLReader(); 

      /** Send URL to parse XML Tags */ 
      URL sourceUrl = new URL("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=75"); 

      /** Create handler to handle XML Tags (extends DefaultHandler) */ 
      MyXMLHandler myXMLHandler = new MyXMLHandler(); 
      xr.setContentHandler(myXMLHandler); 
      xr.parse(new InputSource(sourceUrl.openStream())); 

     } catch (Exception e) { 
      System.out.println("XML Pasing Excpetion = " + e); 
     } 

     /** Get result from MyXMLHandler SitlesList Object */ 
     sitesList = MyXMLHandler.sitesList; 

     /** Assign textview array lenght by arraylist size */ 

     nemotecnico = new TextView[sitesList.getNemotecnico().size()]; 
     variacion = new TextView[sitesList.getVariacion().size()]; 
     precio = new TextView[sitesList.getPrecio().size()]; 


     /** Set the result text in textview and add it to layout */ 
     for (int i = 0; i < sitesList.getRegistro().size(); i++) { 

      variacion[i] = new TextView(this); 
      variacion[i].setText(" " +sitesList.getVariacion().get(i)); 

      nemotecnico[i] = new TextView(this); 
      nemotecnico[i].setText(" " +sitesList.getNemotecnico().get(i)); 

      precio[i] = new TextView(this); 
      precio[i].setText(" " + sitesList.getPrecio().get(i)); 

      Pattern pattern = Pattern.compile("^([a-z: ]*)?+(\\+?[0-9]+([,\\.][0-9]*)?)$"); 
      Matcher matcher = pattern.matcher(sitesList.getVariacion().get(i)); 
      if (!matcher.matches()) 

       variacion[i].setTextColor(Color.parseColor("#ff0000")); 
      else 
       variacion[i].setTextColor(Color.parseColor("#008000")); 


     } 
     for (int i = 0; i < 80; i++) { 
      tr[i] = new TableRow(this); 

      tr[i].addView(nemotecnico[i], new TableRow.LayoutParams(1)); 
      tr[i].addView(precio[i], new TableRow.LayoutParams(2)); 
      tr[i].addView(variacion[i], new TableRow.LayoutParams(3)); 

      layout.addView(tr[i], new TableLayout.LayoutParams()); 

     } 
     /** Set the layout view to display */ 
     setContentView(layout); 

    }  
} 

Как вы видите, в моем коде:

TableLayout layout =(TableLayout)findViewById(R.id.tabla); 

TableRow tr[] = new TableRow[80]; 

TextView variacion[]; 
TextView nemotecnico[]; 
TextView precio[]; 

И показать TextView в TableRow

for (int i = 0; i < 80; i++) { 
    tr[i] = new TableRow(this); 

    tr[i].addView(nemotecnico[i], new TableRow.LayoutParams(1)); 
    tr[i].addView(precio[i], new TableRow.LayoutParams(2)); 
    tr[i].addView(variacion[i], new TableRow.LayoutParams(3)); 

    layout.addView(tr[i], new TableLayout.LayoutParams()); 

} 
/** Set the layout view to display */ 
setContentView(layout); 

Но я не могу поместите HorizontalScrollView и ScrollView, потому что мой Xml показан ниже.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/tabla" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/fondo" > 

</TableLayout> 

Очень ценю вашу помощь, спасибо !.

ответ

1

Я не понимаю, почему вы не можете обернуть всю таблицу в виде вертикального и горизонтального прокрутки или обернуть отдельные ячейки (в зависимости от того, что вы предпочитаете). Первый вариант выглядит следующим образом:

<ScrollView ...> 
    <HorizontalScrollView ...> 
     <TableLayout ...> 
    </HorizontalScrollView> 
</ScrollView> 

Однако это только позволяет пользователю прокручивать по горизонтали или по вертикали для каждого жеста, не по диагонали. Но этот вопрос касается создания двухмерного ScrollView: Scrollview vertical and horizontal in android.

+0

спасибо! отлично работает: D –

Смежные вопросы