Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 10.07 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Views are not diosplayed on spinner's onitemseleted event
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout android:id="@+id/LinearLayout01"
  4.     xmlns:android="http://schemas.android.com/apk/res/android"
  5.     android:orientation="vertical"
  6.     android:layout_height="fill_parent"
  7.     android:layout_width="fill_parent"
  8.     android:background="#ffffff">
  9.  
  10.  
  11.     <LinearLayout android:layout_width="fill_parent"
  12.         android:layout_height="wrap_content"
  13.         android:background="#3e7cc7"
  14.         android:orientation="horizontal">
  15.         <TableLayout android:layout_width="fill_parent"
  16.             android:layout_height="wrap_content">
  17.             <TableRow>
  18.                 <Button android:layout_width="fill_parent"
  19.                     android:layout_height="wrap_content"
  20.                     android:layout_weight="1"
  21.  
  22.                     android:background="@android:color/transparent"
  23.                     android:drawableLeft="@drawable/vcsheader" />
  24.                 <Button android:layout_width="fill_parent"
  25.                     android:layout_height="wrap_content"
  26.                     android:layout_weight="1"
  27.  
  28.                     android:background="@android:color/transparent"
  29.                     android:drawableRight="@drawable/ecubixheader" />
  30.  
  31.             </TableRow>
  32.         </TableLayout>
  33.     </LinearLayout>
  34.  
  35.     <LinearLayout android:layout_width="fill_parent"
  36.         android:layout_height="wrap_content"
  37.         android:background="#b0d1f4"
  38.         android:orientation="horizontal">
  39.         <TableLayout android:layout_width="fill_parent"
  40.             android:layout_height="wrap_content">
  41.             <TableRow>
  42.                 <Button android:text=" "
  43.                     android:id="@+id/btnBack"
  44.                     android:layout_width="wrap_content"
  45.                     android:layout_height="wrap_content"
  46.                     android:background="@drawable/back"></Button>
  47.  
  48.  
  49.                 <TextView android:layout_width="fill_parent"
  50.                     android:layout_height="wrap_content"
  51.                     android:text="NW Day"
  52.                     android:textColor="#508cd4"
  53.                     android:textStyle="bold"
  54.                     android:gravity="center"
  55.                     android:layout_weight="2" />
  56.  
  57.  
  58.             </TableRow>
  59.         </TableLayout>
  60.  
  61.     </LinearLayout>
  62.  
  63.     <LinearLayout android:layout_width="fill_parent"
  64.         android:layout_height="wrap_content"
  65.         android:orientation="horizontal"
  66.         android:background="#fcc2ae">
  67.  
  68.         <TextView android:layout_width="fill_parent"
  69.             android:layout_height="wrap_content"
  70.             android:text="Alex "
  71.             android:id="@+id/txtDate"
  72.             android:gravity="center"
  73.             android:textColor="#000000"
  74.             android:paddingLeft="10dp" />
  75.  
  76.     </LinearLayout>
  77.  
  78.  
  79.     <LinearLayout android:layout_width="fill_parent"
  80.         android:layout_height="wrap_content"
  81.         android:orientation="horizontal"
  82.         android:background="#ffffff">
  83.         <Spinner android:layout_weight="1"
  84.             android:layout_width="fill_parent"
  85.             android:id="@+id/spinnwday"
  86.             android:layout_height="wrap_content"></Spinner>
  87.  
  88.     </LinearLayout>
  89.     <LinearLayout android:layout_width="fill_parent"
  90.             android:layout_height="wrap_content"
  91.         android:orientation="vertical"
  92.         android:id="@+id/llLeaves">
  93.  
  94.         <RadioGroup android:id="@+id/rdgroup"
  95.             android:layout_width="wrap_content"
  96.             android:layout_height="wrap_content">
  97.  
  98.         </RadioGroup>
  99.  
  100.     </LinearLayout>
  101.     <ScrollView
  102.         android:id="@+id/NWdayOthersscroll"
  103.         android:layout_height="wrap_content"
  104.         android:layout_width="fill_parent">
  105.         <LinearLayout android:layout_width="fill_parent"
  106.             android:layout_height="wrap_content"
  107.             android:orientation="vertical"
  108.             android:id="@+id/llOthers">
  109.  
  110.  
  111.  
  112.         </LinearLayout>
  113.     </ScrollView>
  114.  
  115.  
  116.  
  117.     </LinearLayout>
  118.        
  119. package org.mypkg;
  120.  import java.util.ArrayList;
  121.  
  122.     import android.app.Activity;
  123.     import android.database.Cursor;
  124.     import android.graphics.Color;
  125.     import android.os.Bundle;
  126.     import android.util.Log;
  127.     import android.view.View;
  128.     import android.view.ViewGroup.LayoutParams;
  129.     import android.widget.AdapterView;
  130.     import android.widget.AdapterView.OnItemSelectedListener;
  131.     import android.widget.ArrayAdapter;
  132.     import android.widget.CompoundButton;
  133.     import android.widget.CompoundButton.OnCheckedChangeListener;
  134.     import android.widget.CheckBox;
  135.     import android.widget.LinearLayout;
  136.     import android.widget.RadioButton;
  137.     import android.widget.RadioGroup;
  138.     import android.widget.ScrollView;
  139.     import android.widget.Spinner;
  140.     import android.widget.TableRow;
  141.     import android.widget.TextView;
  142.     import android.widget.Toast;
  143.  
  144.  
  145. public class NWDay1 extends Activity {
  146.  
  147.     String[] leaveType = { "Leave", "Others" };
  148.     private Cursor crLeaves,crOthers;
  149.     DatabaseHelper dbHelper;
  150.     String varSMSReasonCode, varRemarks,chkid;
  151.     TextView txtvarSMSReasonCode,txtvarRemarks;
  152.     RadioGroup rdgrp;
  153.     RadioButton rdbtn;
  154.     CheckBox cbOthers;
  155.     ScrollView scroll;
  156.     LinearLayout llMainLeaves,llOthers ;
  157.     ArrayList< String> listGLCodeTempVal;
  158.     ArrayList<String> listSMSReasonCode;
  159.     int GlCode;
  160.     int tempref_SMSGlCode= 0;
  161.  
  162.     @Override
  163.     protected void onCreate(Bundle savedInstanceState) {
  164.         // TODO Auto-generated method stub
  165.         super.onCreate(savedInstanceState);
  166.         setContentView(R.layout.nwday1);
  167.         Spinner spinnwday = (Spinner) findViewById(R.id.spinnwday);
  168.  
  169.         ArrayAdapter<String> spinAdapter = new ArrayAdapter<String>(this,
  170.                 android.R.layout.simple_spinner_item, leaveType);
  171.         spinnwday.setAdapter(spinAdapter);
  172.         dbHelper = new DatabaseHelper(this);
  173.  
  174.         crLeaves = dbHelper.getLeaveReasons();
  175.         startManagingCursor(crLeaves);
  176.         // llMainLeaves.setVisibility(View.GONE);
  177.         // llOthers.setVisibility(View.GONE);
  178.  
  179.         spinnwday.setOnItemSelectedListener(new OnItemSelectedListener() {
  180.  
  181.             public void onItemSelected(AdapterView<?> parent, View view,
  182.                     int position, long id) {
  183.                 // TODO Auto-generated method stub
  184.                 if (position == 0) {
  185.  
  186.                     Log.d("position:", "" + position);
  187.  
  188.                     drawleaveinterface();
  189.                     /*
  190.                      * if(scroll.getVisibility()==View.VISIBLE){
  191.                      * scroll.setVisibility(View.GONE); }
  192.                      */
  193.  
  194.                 } else {
  195.                     Log.d("Position", "" + position);
  196.  
  197.                     drawothersinterface();
  198.                 }
  199.             }
  200.  
  201.             public void onNothingSelected(AdapterView<?> arg0) {
  202.                 // TODO Auto-generated method stub
  203.  
  204.             }
  205.         });
  206.  
  207.     }
  208.  
  209.  
  210.  
  211.  
  212. public void drawleaveinterface() {
  213.         // scroll.setVisibility(View.GONE);
  214.         // llOthers.removeAllViews();
  215.         llMainLeaves = (LinearLayout) findViewById(R.id.llLeaves);
  216.         rdgrp = (RadioGroup) findViewById(R.id.rdgroup);
  217.         while (crLeaves.moveToNext()) {
  218.             GlCode = crLeaves.getInt(crLeaves.getColumnIndex("_id"));
  219.  
  220.             Log.d("added", "id" + GlCode);
  221.             varSMSReasonCode = crLeaves.getString(crLeaves
  222.                     .getColumnIndex("varSMSReasonCode"));
  223.             varRemarks = crLeaves.getString(crLeaves
  224.                     .getColumnIndex("varRemarks"));
  225.  
  226.             LinearLayout llLeaves = new LinearLayout(this);
  227.             llLeaves.setBackgroundColor(Color.BLACK);
  228.             rdbtn = new RadioButton(NWDay1.this);
  229.             rdbtn.setId(GlCode);
  230.             rdbtn.setText(varSMSReasonCode + " - " + varRemarks);
  231.             rdbtn.setTextColor(Color.BLACK);
  232.  
  233.  
  234.             rdbtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  235.  
  236.                 public void onCheckedChanged(CompoundButton arg0,
  237.                  boolean arg1) {
  238.                     // TODO Auto-generated method stub
  239.                 if(rdbtn.isChecked()){
  240.                     tempref_SMSGlCode = rdbtn.getId();
  241.  
  242.                 }
  243.                 }
  244.             });
  245.             // txtvarSMSReasonCode = new TextView(NWDay1.this);
  246.             // txtvarRemarks = new TextView(this);
  247.             // rdbtn.setText(varSMSReasonCode + " - " + varRemarks);
  248.             // txtvarSMSReasonCode.setText(varSMSReasonCode + " - " +
  249.             // varRemarks);
  250.             // txtvarRemarks.setTextColor(Color.MAGENTA);
  251.             // txtvarSMSReasonCode.setHeight(50);
  252.  
  253.             rdgrp.addView(rdbtn);
  254.             // llLeaves.addView(rdgrp);
  255.             // llLeaves.addView(rdbtn);
  256.             llMainLeaves.addView(llLeaves);
  257.             // llOthers.setVisibility(View.GONE);
  258.         }
  259.     }
  260.  
  261.  
  262. public void drawothersinterface() {
  263.         llMainLeaves.setVisibility(View.GONE);
  264.         crOthers = dbHelper.getLeaveReasonsOther();
  265.         startManagingCursor(crOthers);
  266.         scroll = (ScrollView) findViewById(R.id.NWdayOthersscroll);
  267.  
  268.         while (crOthers.moveToNext()) {
  269.             chkid = (crOthers.getString(crOthers.getColumnIndex("_id")));
  270.  
  271.             Log.d("added", "id" + chkid);
  272.             varSMSReasonCode = crOthers.getString(crOthers
  273.                     .getColumnIndex("varSMSReasonCode"));
  274.             varRemarks = crOthers.getString(crOthers
  275.                     .getColumnIndex("varRemarks"));
  276.  
  277.             llOthers = (LinearLayout) findViewById(R.id.llOthers);
  278.             cbOthers = new CheckBox(this);
  279.  
  280.  
  281.  
  282.             cbOthers.setWidth(10);
  283.             cbOthers.setHeight(50);
  284.             cbOthers.setText(" " + varSMSReasonCode + "" + "-" + ""
  285.                     + varRemarks);
  286.             cbOthers.setTextColor(Color.BLACK);
  287.             cbOthers.setId(Integer.valueOf(chkid));
  288.  
  289.             llOthers.addView(cbOthers);
  290.             /*
  291.              * if(!(listGLCodeTempVal.toString().equals(""))){
  292.              *
  293.              * if(cbOthers.isChecked() == true){
  294.              * listGLCodeTempVal.add(String.valueOf(cbOthers.getId()));
  295.              * //listSMSReasonCode.add(varSMSReasonCode); }
  296.              *
  297.              * }
  298.              */
  299.             Log.d(" check id::::::", "" + cbOthers.getId());
  300.         }
  301.  
  302.     }
  303. }