package com.sometrik.framework;

import java.util.ArrayList;
import java.util.List;

import com.sometrik.vapu.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FWAdapter extends ArrayAdapter<View> {

  private List<View> viewList;
  private ArrayList<AdapterData> dataList;
  private FrameWork frame;
  private LinearLayout.LayoutParams listItemParams;
  
  public FWAdapter(Context context, List<View> viewList) {
    super(context, 0, viewList);
    this.frame = (FrameWork) context;
    dataList = new ArrayList<AdapterData>();
    listItemParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT);
    listItemParams.weight = 1;
    listItemParams.leftMargin = 2;
  }

  public ArrayList<String> getDataRow(int rowId) {
    if (dataList.size() >= rowId + 1) {
      return dataList.get(rowId).stringList;
    }
    Log.d("adapter", "no row found");
    return null;
  }
  
  public void addItem(ArrayList<String> cellItems){
    dataList.add(new AdapterData(cellItems));
  }

  @Override
  public int getCount() {
    return dataList.size();
  }

  @Override
  public long getItemId(int arg0) {
    return 0;
  }
  
  @Override
  public void clear(){
    dataList = new ArrayList<AdapterData>();
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    LinearLayout layout = new LinearLayout(frame);

    AdapterData data = dataList.get(position);
    
    for (int i = 0; i < data.getSize(); i++){
      TextView txtFirst = new TextView(frame);
      txtFirst.setLayoutParams(listItemParams);
      layout.addView(txtFirst);
      txtFirst.setText(data.getData(i));
    }

    return layout;
  }
  
  public class AdapterData {

    private ArrayList<String> stringList;

    public AdapterData(ArrayList<String> stringList) {
      this.stringList = stringList;
    }

    public int getSize() {
      return stringList.size();
    }

    public String getData(int position) {

      if (position < stringList.size()) {
	return stringList.get(position);
      } else {
	return stringList.get(0);
      }
    }

  }
}



@@ -485,24 +485,58 @@
 %3E dataList;%0A
+  private AdapterData columnData;%0A
   private Fr
@@ -550,16 +550,16 @@
  frame;%0A
-
   privat
@@ -776,24 +776,83 @@
 terData%3E();%0A
+    columnData = new AdapterData(new ArrayList%3CString%3E());%0A
     listItem
@@ -1306,24 +1306,113 @@
 Items));%0A  %7D
+%0A  %0A  public void addColumn(String columnText)%7B%0A    columnData.addString(columnText);%0A  %7D
 %0A%0A  @Overrid
@@ -1812,20 +1812,16 @@
 ition);%0A
-    
 %0A    for
@@ -1857,16 +1857,17 @@
 (); i++)
+ 
 %7B%0A      
@@ -2132,16 +2132,56 @@
 ingList;
+%0A    private boolean columnData = false;
 %0A%0A    pu
@@ -2266,24 +2266,103 @@
 gList;%0A    %7D
+%0A    %0A    public void addString(String text)%7B%0A      stringList.add(text);%0A    %7D
 %0A%0A    public
@@ -2455,25 +2455,24 @@
 position) %7B%0A
-%0A
       if (po
@@ -2577,16 +2577,16 @@
 get(0);%0A
-
       %7D%0A
@@ -2586,22 +2586,98 @@
      %7D%0A    %7D
+%0A    %0A    public ArrayList%3CString%3E getList()%7B%0A      return stringList;%0A    %7D
 %0A%0A  %7D%0A%7D%0A%0A%0A

Add ColumnData variable