2014-11-17 5 views
2

모든 것을 시도했지만 저장 버튼을 사용 중지 할 수 없습니다. 나는 onCreate의 끝에 그것을 썼다. 사실 나는 사용자가 몇 가지 노트를 편집하고 스피너에서 카테고리를 선택하면 자동으로 활성화되어 달성했습니다. 하지만 사용자가이 페이지에있을 때 먼저 버튼을 비활성화해야합니다. 사용자가 자신의 작업량을 투여하면 사용할 수 있습니다. 하지만이 저장 버튼을 어떻게 비활성화해야합니까?android에서 버튼을 사용 중지 할 수 없습니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bbk_base_all" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:paddingRight="3dp" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@+id/txtwelcome" /> 

    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="130dp" 
     android:gravity="center" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="30dp" 
      android:background="@drawable/buttonborder" 
      android:paddingTop="10dp" > 

      <TextView 
       android:id="@+id/tv_titleDate" 
       android:layout_width="150dp" 
       android:layout_height="wrap_content" 
       android:gravity="left" 
       android:paddingLeft="25dp" 
       android:text="Transaction Date" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" 
       android:textStyle="bold|italic" /> 

      <TextView 
       android:id="@+id/tv_getDate" 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:gravity="left" 
       android:paddingBottom="5dp" 
       android:paddingLeft="30dp" 
       android:text="Date" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/buttonborder" 
      android:paddingTop="10dp" > 

      <TextView 
       android:id="@+id/tv_titleParticulars" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="left" 
       android:paddingLeft="25dp" 
       android:text="Particulars" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" 
       android:textStyle="bold|italic" /> 

      <TextView 
       android:id="@+id/tv_getParticular" 
       android:layout_width="30dp" 
       android:layout_height="wrap_content" 
       android:ems="50" 
       android:gravity="left" 
       android:maxLines="4" 
       android:paddingLeft="30dp" 
       android:text="Particulars" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="250dp" 
      android:layout_height="30dp" 
      android:background="@drawable/buttonborder" 
      android:paddingTop="10dp" > 

      <TextView 
       android:id="@+id/tv_titleAmount" 
       android:layout_width="150dp" 
       android:layout_height="wrap_content" 
       android:gravity="left" 
       android:paddingLeft="25dp" 
       android:text="Amount" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" 
       android:textStyle="bold|italic" /> 

      <TextView 
       android:id="@+id/tv_getAmount" 
       android:layout_width="125dp" 
       android:layout_height="wrap_content" 
       android:gravity="left" 
       android:paddingLeft="30dp" 
       android:text="Amount" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="250dp" 
      android:layout_height="30dp" 
      android:background="@drawable/buttonborder" 
      android:paddingTop="10dp" > 

      <TextView 
       android:id="@+id/tv_titleBalance" 
       android:layout_width="150dp" 
       android:layout_height="25dp" 
       android:gravity="left" 
       android:paddingLeft="25dp" 
       android:text="Balance Amount" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" 
       android:textStyle="bold|italic" /> 

      <TextView 
       android:id="@+id/tv_getBalance" 
       android:layout_width="125dp" 
       android:layout_height="25dp" 
       android:gravity="left" 
       android:paddingLeft="30dp" 
       android:text="Balance" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="250dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/buttonborder" 
      android:paddingTop="10dp" > 

      <TextView 
       android:id="@+id/tv_titleCategory" 
       android:layout_width="150dp" 
       android:layout_height="25dp" 
       android:gravity="center_vertical" 
       android:paddingLeft="25dp" 
       android:text="Select Category" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" 
       android:textStyle="bold|italic" /> 

      <Spinner 
       android:id="@+id/spn_selectCategory" 
       android:layout_width="125dp" 
       android:layout_height="wrap_content" 
       android:gravity="left" 
       android:paddingLeft="30dp" 
       android:textColor="#FFFFFF" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="250dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/buttonborder" 
      android:paddingTop="10dp" > 

      <TextView 
       android:id="@+id/tv_titleNotes" 
       android:layout_width="150dp" 
       android:layout_height="25dp" 
       android:gravity="center_vertical" 
       android:paddingLeft="25dp" 
       android:text="Notes" 
       android:textColor="#FFFFFF" 
       android:textSize="15sp" 
       android:textStyle="bold|italic" /> 

      <EditText 
       android:id="@+id/et_getNotes" 
       android:layout_width="30dp" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/tableLayout1" 
       android:layout_toLeftOf="@+id/imageView1" 
       android:hint="Add Your Own Notes" 
       android:maxLines="3" 
       android:paddingLeft="30dp" 
       android:textColor="#FFFFFF" > 
      </EditText> 
     </TableRow> 
    </TableLayout> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="70dp" 
     android:gravity="center" 
     android:text="Transaction Details" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#FFFFFF" 
     android:textSize="24dp" 
     android:textStyle="bold|italic" /> 

    <Button 
     android:id="@+id/btnSave" 
     android:layout_width="110dp" 
     android:layout_height="30dp" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/tableLayout1" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="30dp" 
     android:background="@drawable/normalbuttonborder" 
     android:text="Save" 
     android:textSize="16sp" 
     android:textStyle="bold" 
     android:enabled="false" /> 

    <Button 
     android:id="@+id/btnBack" 
     android:layout_width="110dp" 
     android:layout_height="30dp" 
     android:layout_alignBaseline="@+id/btnSave" 
     android:layout_alignBottom="@+id/btnSave" 
     android:layout_marginRight="20dp" 
     android:layout_toLeftOf="@+id/imageView1" 
     android:background="@drawable/normalbuttonborder" 
     android:text="Back" 
     android:textSize="16sp" 
     android:textStyle="bold" /> 

</RelativeLayout> 

이 제발 도와주세요 :

여기 여기 내 xml 파일 내 OfflinePBDetails.java 클래스

package passbookManager; 

import java.io.FileInputStream; 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.Properties; 

import logs.TraceLog; 
import mainApplication.*; 

import forbes.mPassbook.R; 
import databaseClasses.DBAccountStatement; 
import databaseClasses.DBCategoryMaster; 
import android.app.Activity; 
import android.app.ActionBar; 
import android.app.Fragment; 
import android.content.Intent; 
import android.database.Cursor; 
import android.graphics.Color; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.os.Environment; 
import android.os.Handler; 
import android.os.Message; 
import android.os.StrictMode; 
import android.text.Editable; 
import android.text.TextWatcher; 
import android.view.KeyEvent; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.View.OnKeyListener; 
import android.view.ViewGroup; 
import android.view.inputmethod.EditorInfo; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemSelectedListener; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Spinner; 
import android.widget.TextView; 
import android.widget.Toast; 
import android.os.Build; 

public class OfflinePBDetails extends Activity implements OnItemSelectedListener 
{ 
    TextView tvDate; 
    TextView tvAmount; 
    TextView tvBalance; 
    TextView tvParticular; 
    TextView tvTitleAmount; 
    EditText etNotes; 

    Spinner spinnerCategory; 

    Button btnBack; 
    Button btnSave; 

    String file_Path; 
    Properties properties_config; 

    long sessionTimeout; 

    String passTransId; 
    String passDate; 
    String passParticular; 
    String passDebitCreditIndicator; 
    String passAmount; 
    String passTransString; 
    String passBalance; 
    String passFlag; 

    String transId; 
    String notes; 

    int countDBRows; 
    int countDBColumns; 

    String dbSubCategory; 
    String dbNotes; 

    String selectedCategory; 
    String[][] tableCategory ; 
    ArrayList<String> categoryIncome; 
    ArrayList<String> categoryExpense; 
    ArrayAdapter<String> adapterSelect; 

    DBCategoryMaster dbCMaster; 
    DBAccountStatement dbStatement; 


     TraceLog tc = new TraceLog(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     ActionBar bar=getActionBar(); 
     bar.hide(); 
     setContentView(R.layout.activity_offline_pbdetails); 

     dbCMaster = new DBCategoryMaster(this); 
     dbStatement = new DBAccountStatement(this); 

     file_Path=Environment.getExternalStorageDirectory()+ "/Android/data/forbes.mPassbook/"; 
     readConfigFileDetails(); 

     if(Build.VERSION.SDK_INT >= 9) 
     { 
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
      StrictMode.setThreadPolicy(policy); 
     } 

     try 
     { 

      tvDate = (TextView)findViewById(R.id.tv_getDate); 
      tvParticular = (TextView)findViewById(R.id.tv_getParticular); 
      tvAmount = (TextView)findViewById(R.id.tv_getAmount); 
      tvTitleAmount = (TextView)findViewById(R.id.tv_titleAmount); 
      tvBalance = (TextView)findViewById(R.id.tv_getBalance); 
      spinnerCategory = (Spinner)findViewById(R.id.spn_selectCategory); 
      etNotes = (EditText)findViewById(R.id.et_getNotes); 
      btnBack = (Button)findViewById(R.id.btnBack); 
      btnSave = (Button)findViewById(R.id.btnSave); 

      Intent intent = getIntent(); 
      passTransId = intent.getExtras().getString("TransactionId"); 
      passDate = intent.getExtras().getString("Date"); 
      passParticular = intent.getExtras().getString("Particular"); 

      passAmount = intent.getExtras().getString("Amount"); 
      passTransString = intent.getExtras().getString("TransString"); 
      passDebitCreditIndicator = intent.getExtras().getString("Indicator"); 
      passBalance = intent.getExtras().getString("Balance"); 
      passFlag = intent.getExtras().getString("FilterFlag"); 

      tvDate.setText(passDate); 
      tvParticular.setText(passParticular); 
      tvTitleAmount.setText(passTransString); 

      if(tvTitleAmount.getText().equals("Withdrawal Amount")) 
      { 
       tvAmount.setTextColor(Color.RED); 
      } 
      else 
      { 
       tvAmount.setTextColor(Color.rgb(48,128,20)); 
      } 

      String trimAmount = passAmount.trim(); 
      String trimBalance = passBalance.trim(); 
      tvAmount.setText(trimAmount); 
      tvBalance.setText(trimBalance); 

      etNotes.addTextChangedListener(new TextWatcher() 
      { 
       @Override 
       public void afterTextChanged(Editable arg0) 
       { 
        btnSave.setEnabled(true); 
        resetDisconnectTimer(); 
        //     Toast.makeText(getApplicationContext(), "After Typing", Toast.LENGTH_LONG).show(); 
       } 

       @Override 
       public void beforeTextChanged(CharSequence s, int start, int count, int after) 
       { 
        //     Toast.makeText(getApplicationContext(), "Before Typing", Toast.LENGTH_LONG).show(); 
       } 

       @Override 
       public void onTextChanged(CharSequence s, int start, int before, int count) 
       { 
        //     Toast.makeText(getApplicationContext(), "Typing", Toast.LENGTH_LONG).show(); 
       } 
      }); 

      btnBack.setOnClickListener(new OnClickListener() 
      { 
       @Override 
       public void onClick(View v) 
       { 
        if(passFlag.equalsIgnoreCase("OfflinePB")) 
        { 
         Intent i = new Intent(OfflinePBDetails.this,OfflinePB.class); 
         i.putExtra("filterFlag","notes");/**********Code to go back to DisplayFilter Page***************************/ 
         i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(i); 
         finish(); 
        } 
        else if(passFlag.equalsIgnoreCase("notes")) 
        { 
         Intent i = new Intent(OfflinePBDetails.this,DisplayFilters.class); 
         i.putExtra("filterFlag","notes"); 
         i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(i); 
         finish(); 
        } 
        else if(passFlag.equalsIgnoreCase("transfer")) 
        { 
         Intent i = new Intent(OfflinePBDetails.this,DisplayFilters.class); 
         i.putExtra("filterFlag","transfer"); 
         i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(i); 
         finish(); 
        } 
        else if(passFlag.equalsIgnoreCase("cheque")) 
        { 
         Intent i = new Intent(OfflinePBDetails.this,DisplayFilters.class); 
         i.putExtra("filterFlag","cheque"); 
         i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(i); 
         finish(); 
        } 
       } 
      }); 

      btnSave.setOnClickListener(new OnClickListener() 
      { 
       @Override 
       public void onClick(View v) 
       { 
        try 
        { 
         btnSave.setEnabled(false); 
         transId = passTransId; 
         notes = etNotes.getText().toString(); 
         //     if(spinnerCategory.length()==0) 
         //     {      
         //      spinnerCategory.setError("Please Enter mPIN  ");      
         //      mPin.requestFocus(); 
         //     } 
         //     else 
         //      if(notes.trim().length()==0) 
         //     { 
         //      etNotes.setError("Please Add Your Notes   "); 
         //      etNotes.setText(null);     
         //      etNotes.requestFocus(); 
         //     } 

         if(dbStatement.updatePassbook(transId, selectedCategory, notes)) 
         { 
          Toast.makeText(getApplicationContext(), "Data Updated Successfully", Toast.LENGTH_LONG).show(); 
          //      Toast.makeText(getApplicationContext(), "selectedCategory : " + selectedCategory, Toast.LENGTH_LONG).show(); 
          //      Toast.makeText(getApplicationContext(), "notes : " + notes, Toast.LENGTH_LONG).show(); 
         } 
        } 

        catch(Exception e) 
        { 
         tc.WriteToTransactionLog("Exception: OfflinePBDetails.java Save.setOnClickListener():- "+e.toString()); 
        } 
       } 
      }); 

      dbGetCategoryList(); 
      btnSave.setEnabled(false); 
     } 
     catch(Exception e) 
     { 
      tc.WriteToTransactionLog("Exception: OfflinePBDetails.java onCreate():- "+e.toString()); 
     } 

    } 

    public void dbGetCategoryList() 
    { 
     int element; 

     try 
     { 

      Cursor rs = dbCMaster.getData(); 

      countDBRows = rs.getCount(); 
      countDBColumns = rs.getColumnCount(); 

      tableCategory = new String[countDBRows][countDBColumns]; 

      rs.moveToFirst(); 

      for(element = 0; element < countDBRows; element++) 
      {  
       tableCategory[element][0] = rs.getString(0); // subCategory 
       tableCategory[element][1] = rs.getString(1); // Category 
       tableCategory[element][2] = rs.getString(2); // transType 

       rs.moveToNext(); 

       //      String finalData = tableCategory[element][0]+ " " + tableCategory[element][1] 
       //        + " " + tableCategory[element][2]; 
       //      Toast.makeText(getApplicationContext(), "finalData : " + finalData, Toast.LENGTH_SHORT).show(); 
      } 

      rs.close(); 

      showCategoryList(); 
     } 
     catch(Exception e) 
     { 
      tc.WriteToTransactionLog("Exception: OfflinePBDetails.java dbGetCategoryList():- "+e.toString()); 
     } 
    } 

    public void showCategoryList() 
    { 
     int i = 0; 
     int j = 0; 

     int element; 
     String transType; 

     categoryIncome = new ArrayList<String>(); 
     categoryExpense = new ArrayList<String>(); 
     //  categoryIncome = new String[2]; 
     //  categoryExpense = new String[3]; 

     try 
     { 

      for(element = 0; element < countDBRows; element++) 
      {  

       transType = tableCategory[element][2]; 

       //    Toast.makeText(getApplicationContext(), "transType : " + transType, Toast.LENGTH_SHORT).show(); 
       //    Toast.makeText(getApplicationContext(), "passDebitCreditIndicator : " + passDebitCreditIndicator, Toast.LENGTH_SHORT).show(); 

       if(passDebitCreditIndicator.equalsIgnoreCase("D")) 
       { 

        if(passDebitCreditIndicator.equalsIgnoreCase(transType)) 
        { 
         if(tableCategory[element][0].equalsIgnoreCase("Others-E")) 
         { 
          categoryExpense.add("Others"); 
         } 
         else 
         { 
          categoryExpense.add(tableCategory[element][0]); 
         } 
         //      Toast.makeText(getApplicationContext(), "categoryExpense : " + categoryExpense, Toast.LENGTH_SHORT).show(); 
         i++; 
        } 
       } 

       else 
       { 
        if(passDebitCreditIndicator.equalsIgnoreCase(transType)) 
        { 
         if(tableCategory[element][0].equalsIgnoreCase("Others-I")) 
         { 
          categoryIncome.add("Others"); 
         } 
         else 
         { 
          categoryIncome.add(tableCategory[element][0]); 
         } 
         //      Toast.makeText(getApplicationContext(), "categoryIncome : " + categoryIncome, Toast.LENGTH_SHORT).show(); 
         j++; 
        } 
       } 
      } 


      if(passDebitCreditIndicator.equalsIgnoreCase("D")) 
      { 
       adapterSelect = new ArrayAdapter<String>(this, R.layout.spinner_pb_details,categoryExpense); 
       //    adapterSelect = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categoryExpense); 
      } 
      else 
      { 
       adapterSelect = new ArrayAdapter<String>(this, R.layout.spinner_pb_details,categoryIncome); 
       //    adapterSelect = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categoryIncome); 
      } 

      adapterSelect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

      spinnerCategory.setAdapter(adapterSelect); 

      spinnerCategory.setOnItemSelectedListener(this); 

      checkDBData(); 

      if(dbSubCategory.equalsIgnoreCase("Others-E") || dbSubCategory.equalsIgnoreCase("Others-I")) 
      { 
       dbSubCategory = "Others"; 
      } 

      ArrayAdapter myAdap = (ArrayAdapter) spinnerCategory.getAdapter(); //cast to an ArrayAdapter 
      int spinnerPosition = myAdap.getPosition(dbSubCategory); 

      //set the default according to value 
      spinnerCategory.setSelection(spinnerPosition); 

      etNotes.setText(dbNotes); 

      // to disable save button after notes is filled with note from db and item is selected from item listner 
     } 
     catch(Exception e) 
     { 
      tc.WriteToTransactionLog("Exception: OfflinePBDetails.java showCategoryList():- "+e.toString()); 
     } 
    } 

    @Override 
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) 
    { 
     //  try 
     //  { 
     spinnerCategory.setSelection(position); 
     selectedCategory = (String) spinnerCategory.getSelectedItem(); 

     if(passDebitCreditIndicator.equalsIgnoreCase("D")) 
     { 

      if(selectedCategory.equalsIgnoreCase("Others")) 
      { 
       selectedCategory = "Others-E"; 
      } 
      //    else 
      //    { 
      //     selectedCategory = selectedCategory; 
      //    } 
      //    Toast.makeText(getApplicationContext(), "selectedCategory : " + selectedCategory, Toast.LENGTH_SHORT).show(); 
     } 

     else 
     { 

      if(selectedCategory.equalsIgnoreCase("Others")) 
      { 
       selectedCategory = "Others-I"; 
      } 
      //    else 
      //    { 
      //     selectedCategory = (String) spinnerCategory.getSelectedItem(); 
      //    } 
      //   Toast.makeText(getApplicationContext(), "selectedCategory : " + selectedCategory, Toast.LENGTH_SHORT).show(); 
     } 

     btnSave.setEnabled(true); 



     //    switch (position) { 
     //    case 0: 
     //     // Whatever you want to happen when the first item gets selected 
     //     break; 
     //    case 1: 
     //     // Whatever you want to happen when the second item gets selected 
     //     break; 
     //    case 2: 
     //     // Whatever you want to happen when the thrid item gets selected 
     //     break;} 
     //  } 
     //  catch(Exception e) 
     //  { 
     //   Toast.makeText(getApplicationContext(), "Exception onItemSelected : " + e, Toast.LENGTH_SHORT).show(); 
     //  } 
    } 

    public void checkDBData() 
    { 
     try 
     { 
      int element;   
      Cursor rs = dbStatement.getCategory(passTransId); 

      //   int countCategoryRow = rs.getCount(); 
      //   int countCategoryColumn = rs.getColumnCount(); 

      rs.moveToFirst(); 

      dbSubCategory = rs.getString(13); 
      dbNotes = rs.getString(14); 

      rs.moveToNext(); 


      //   String reducedNotes = dbNotes.replace("\n", "").replace("\r", ""); 
      ////   String str =dbNotes.substring(0, 3); 
      //   Toast.makeText(getApplicationContext(), "reducedNotes : " + reducedNotes, Toast.LENGTH_SHORT).show();  
     } 
     catch(Exception e) 
     { 
      tc.WriteToTransactionLog("Exception: OfflinePBDetails.java checkDBData():- "+e.toString()); 
     } 
    } 

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

    } 


    public void readConfigFileDetails() 
    { 
     try 
     { 
      properties_config= new Properties(); 
      FileInputStream fis2 = new FileInputStream(file_Path + "config.properties"); 
      properties_config.load(fis2); 

      sessionTimeout = Long.parseLong(properties_config.getProperty("session_timeout")); 

      fis2.close(); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
      tc.WriteToTransactionLog("Exception: OfflinePBDetails.java readConfigFileDetails():- "+e.toString()); 
     }  
    } 

    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    { 
     if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) 
     { 
      onBackPressed(); 
     } 

     return super.onKeyDown(keyCode, event); 
    } 
    @Override 
    public void onBackPressed() 
    { 
     return; 
    } 


    public void onRestart() 
    { 
     finish(); 
     super.onRestart(); 
     startActivity(new Intent(this, Welcome.class).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 
     finish(); 
    } 


    private Handler disconnectHandler = new Handler(){ 
     public void handleMessage(Message msg) 
     { 

     } 
    }; 

    private Runnable disconnectCallback = new Runnable() 
    { 
     @Override 
     public void run() 
     { 
      Toast.makeText(getApplicationContext(), "Session Expired", Toast.LENGTH_LONG).show(); 
      System.out.println("Session Expired"); 

      Intent intent = new Intent(getApplicationContext(),Welcome.class); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(intent); 
      finish(); 
     } 
    }; 

    public void resetDisconnectTimer() 
    { 
     disconnectHandler.removeCallbacks(disconnectCallback); 
     disconnectHandler.postDelayed(disconnectCallback, sessionTimeout); 
    } 

    public void stopDisconnectTimer() 
    { 
     disconnectHandler.removeCallbacks(disconnectCallback); 
    } 

    @Override 
    public void onUserInteraction() 
    { 
     resetDisconnectTimer(); 
    } 

    @Override 
    public void onResume() 
    { 
     super.onResume(); 
     resetDisconnectTimer(); 
    } 

    @Override 
    public void onStop() 
    { 
     super.onStop(); 
     stopDisconnectTimer(); 
    } 
} 

입니다.

답변

3

는 처음 Button

btnSave = (Button)findViewById(R.id.btnSave); 
btnSave.setEnabled(false); 

이 같은 findViewById 후 문제는 유 Button 것을 가능하게 위치를 Spinner을 가지고 있음을 비활성화합니다. 기본 으로 회 전자의 첫번째 항목이 자동으로 선택되어 있으며에서 onCreate에서 호출 (...)하고 당신의 Button 당신이 가능하게

변경 로직을 수행 할 수있는 작업을 가능 가도록 ButtonSpinner's OnItemSelected(...) 체크인하면 이전에 선택한 값과 현재 선택한 값이 같고 EditText's 값이 변경되지 않은 경우 해당 값을 비활성화하십시오. Button 그렇지 않으면 Button을 활성화하십시오. 이 작업에는 boolean 플래그를 사용하십시오.

+0

나는 그것을 시도했지만 작동하지 않는 이유는 데이터베이스에서 값을 가져 와서 Notes EditText에서 설정하는 onCreate 때문입니다. afterTextChanged (편집 가능한 arg0) 메소드는 데이터베이스에서 값을 설정하는 동안 호출됩니다. 그런 다음 버튼이 활성화됩니다. 하지만 그 활동이 시작되면 그 저장 버튼을 비활성화하고 싶습니다. –

+0

이것은 확실히'Button'을 무력화 시키지만 문제는'Spinner'가있는 곳입니다.By Default ** Spinner의 첫 번째 항목이 자동으로 선택되고 ** UR btn이 할 수있는 것을 가능하게 함 **이 목적을 위해 맞춤 스피너 생성 ** – kId

0

활성화하기 전에 버튼을 비활성화하지 않았습니다.

신고 후 버튼을 비활성화하십시오.

btnSave.setEnabled(false); 

그런 다음 당신이 버튼을 사용하지 않도록 설정할 때문에 당신의 TextChanged 방법

0

에서 활성화 :

btnSave.setEnabled(false); 

또는 설정하려고 : (

btnSave.setClickable(false); 

을는, setEnabled과 함께 거짓)

는 다른 방법으로, 당신의 XML에 선 아래 사용

android:clickable = "false" 
android:enabled = "false" 

와 사용자가 로직 즉 용도에 따라 btnSave에 모두 (사용 & 클릭)를 활성화 (즉, 선택 스피너 항목 후) 노트 편집하여 수행 될 때마다 :

btnSave.setClickable(true); 
btnSave.setEnabled(true); 
관련 문제