public class MainActivity extends Activity {
    private GestureDetector gestureDetector;
    String dateData;
    int choice ;
    public Spinner toList;
    public HashSet<String> keyList = new HashSet<String>();
    public ArrayList<String> temperatures = new ArrayList<String>();
    public ArrayList<String> time = new ArrayList<String>();
    public ArrayList<String> atList=new ArrayList<String>();
    public ArrayList dataList=new ArrayList();
    public ArrayAdapter<String> dataAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gestureDetector = new GestureDetector(this,new SwipeGestureDetector());
        Spinner toList = (Spinner) findViewById(R.id.toList);
        dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, new ArrayList<String>());
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        toList.setAdapter(dataAdapter);
        toList.setOnItemSelectedListener(new CustomOnItemSelectedListener());

    }

............................................

.................................................
 public class CustomOnItemSelectedListener implements OnItemSelectedListener 
    {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos,
                long id) 
        {

            TableLayout tl= (TableLayout)findViewById(R.id.maintable);
            TableRow tr;
            tl.removeAllViews();

            for(int i = 0; i < atList.size(); i++)
            {

                tr = new TableRow(MainActivity.this);
                tr.setLayoutParams(new LayoutParams(
                        LayoutParams.MATCH_PARENT,
                        LayoutParams.WRAP_CONTENT));

                /** Creating another textview **/
                TextView dateValue = new TextView(MainActivity.this);
                dateValue.setText(time.get(i).toString());
                dateValue.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
                dateValue.setPadding(5, 20, 5, 20);
                //dateValue.setBackgroundResource(R.drawable.custom_border);
                dateValue.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                tr.addView(dateValue); // Adding textView to tablerow.          

                // Add the TableRow to the TableLayout
                tl.addView(tr, new TableLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT,
                        LayoutParams.WRAP_CONTENT));
            }
            Toast.makeText(parent.getContext(), "OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
            }

    }

May i know why is the table don't show up ? Before this , i create this table in the PostExecute it work just fine. just now i change it to the onItemSelectedListener there, i doesn't work anymore. may i know what is the problem ?

Related posts

Recent Viewed