2011-11-08 11 views
2

私はこのサイトを初めて利用しています。私の練習のためにアンドロイドアプリケーションをやっています。私は縦型のデザインレイアウトを持っています。レイアウトがランドスケープになるとAndroidアプリケーションが終了する

public class CallLostActivity extends Activity{ 
    private String retailerName = ""; 
    private String retailerCode = ""; 
    private HashMap<String,CallLostReason> callList = new HashMap<String,CallLostReason>(); 
    Spinner cal_lost_reason; 
    String selectedCallReason; 
    SharedPreferences myRoutes; 
    String visitNumber ="0"; 
// private boolean isDefault = false; 
    private String strBusinessUnit =""; 
    private String strExecutive = ""; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     View v = LayoutInflater.from(getParent()).inflate(R.layout.calllost, null); 
     setContentView(v); 
     getParent().getParent().setTitle("Call Lost"); 
     Bundle bundle = this.getIntent().getExtras(); 
     retailerName = bundle.getString("RetailerName"); 
     retailerCode = bundle.getString("RetailerCode"); 

     TextView txtcalostRetailer = (TextView)findViewById(R.id.txtcalostRetailer); 
     txtcalostRetailer.setText(retailerName); 

     //getting logged users stored values from file - using SharedPreferences 
     SharedPreferences myPrefs = this.getSharedPreferences("myLogedPrefs",MODE_WORLD_READABLE); 
     strBusinessUnit = myPrefs.getString("BusinessUnit", ""); 
     strExecutive = myPrefs.getString("Executive", ""); 

     myRoutes = this.getSharedPreferences("myDefalutRoute",MODE_PRIVATE); 
     visitNumber = myRoutes.getString("visitnumber", "-1"); 
    // isDefault = myRoutes.getBoolean("isDefault", false); 

     callList = getAllCallLoast(); 
     ArrayList<String> callLostList = new ArrayList<String>(); 
     callLostList.add("--Select--"); 
     for (Map.Entry<String, CallLostReason> entry : callList.entrySet()) { 
       // String key = entry.getKey(); 
       CallLostReason myCallLostReason = entry.getValue(); 
       callLostList.add(myCallLostReason.getDescription()); 
     } 

     cal_lost_reason = (Spinner) findViewById(R.id.cal_lost_reason); 
     ArrayAdapter<String> reasonAdapter = new ArrayAdapter<String>(v.getContext(),android.R.layout.simple_spinner_item, callLostList); 
     reasonAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item); 
     cal_lost_reason.setAdapter(reasonAdapter); 
     cal_lost_reason.setOnItemSelectedListener(new OnItemSelectedListener() { 

      public void onItemSelected(AdapterView<?> parent, View view,int arg2, long arg3) { 
       selectedCallReason = parent.getSelectedItem().toString(); 
      } 

      public void onNothingSelected(AdapterView<?> arg0) { 

      } 
     }); 

     CheckBox chkCallLost = (CheckBox)findViewById(R.id.chkCallLost); 
     chkCallLost.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
      public void onCheckedChanged(CompoundButton arg0, boolean arg1) { 
       if(arg0.isChecked()){ 
        AlertDialog.Builder routeDefaultQue = new AlertDialog.Builder(SalesActivityGroup.group.getParent()); 
        routeDefaultQue.setMessage("Are you going to do the Sale Lost? "); 
        routeDefaultQue.setCancelable(false); 
        routeDefaultQue.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
         boolean status = saveCalLost("2"); 
         } 

        }); 
        routeDefaultQue.setNegativeButton("No", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          dialog.cancel(); 
         } 
        }); 
        routeDefaultQue.setTitle("Sale Lost..."); 
        routeDefaultQue.show(); 
       }else { 
        AlertDialog.Builder routeDefaultQue = new AlertDialog.Builder(SalesActivityGroup.group.getParent()); 
        routeDefaultQue.setMessage("Are you going to do the Sale Lost? "); 
        routeDefaultQue.setCancelable(false); 
        routeDefaultQue.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
         boolean status = saveCalLost("3"); 
         } 

        }); 
        routeDefaultQue.setNegativeButton("No", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          dialog.cancel(); 
         } 
        }); 
        routeDefaultQue.setTitle("Sale Lost..."); 
        routeDefaultQue.show(); 
       } 
      } 
     }); 
     Button callLostDOk = (Button)findViewById(R.id.callLostDOk); 
     callLostDOk.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 
        AlertDialog.Builder routeDefaultQue = new AlertDialog.Builder(SalesActivityGroup.group.getParent()); 
        routeDefaultQue.setMessage("Are you going to do the Sale Lost? "); 
        routeDefaultQue.setCancelable(false); 
        routeDefaultQue.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
         boolean status = saveCalLost("3"); 
         } 

        }); 
        routeDefaultQue.setNegativeButton("No", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          dialog.cancel(); 
         } 
        }); 
        routeDefaultQue.setTitle("Sale Lost..."); 
        routeDefaultQue.show(); 

       } 
     }); 

     Button callLostCancel = (Button)findViewById(R.id.callLostCancel); 
     callLostCancel.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 
        Intent i = new Intent(getBaseContext(), RetailerOptionActivity.class); 
        Bundle bundle = new Bundle(); 
         bundle.putString("Activity", "CallLostActivity"); 
         bundle.putString("RetailerName", retailerName); 
         bundle.putString("RetailerCode", retailerCode); 
         i.putExtras(bundle); 
        View vi = SalesActivityGroup.group.getLocalActivityManager().startActivity("CallLostActivity", i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); 
        SalesActivityGroup.group.replaceView(vi); 
       } 
     }); 


    } 


    public boolean saveCalLost(String statusValue){ 
     DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this); 
     dbAdapter.openDataBase(); 
     boolean visitStatus = false; 
     Date date = new Date(); 
     DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
     String strDate = formatter.format(date); 
     String sql = "SELECT VisitNumber,VisitSequence,SeletcedDefaultRouteRetailer FROM WMVisitDetail WHERE VisitNumber= ? AND ExecutiveCode=?"; 
     String[]d = new String[]{visitNumber,strExecutive}; 
     ArrayList<?> stringList = dbAdapter.selectRecordsFromDBList(sql, d); 

     if(stringList.size() > 0){ 
      visitStatus = true; 
     } 

     ContentValues initialValues = new ContentValues(); 
     initialValues.put("Status",statusValue); 

     System.out.println("---visitStatus---" +visitStatus); 
     if (visitStatus) { 
      String whereCon = "BusinessUnit ='"+strBusinessUnit+"' AND VisitNumber ='"+visitNumber+"' AND ExecutiveCode ='"+strExecutive+"' AND RetailerCode ='"+retailerCode+ "' AND BusinessUnit='"+strBusinessUnit+"'"; 
      long n = dbAdapter.updateRecordsInDB("WMVisitDetail", initialValues, whereCon, null); 
      System.out.println("----WMVisitDetail---" + n); 
      //WMRetailer update 
      ContentValues retailerValues = new ContentValues(); 
      retailerValues.put("isSaveSales",1); 
      retailerValues.put("UpdateOn",strDate); 
      String strWhereField = " BusinessUnit = '"+ strBusinessUnit+"' AND SalesExecutiveCode ='" +strExecutive + "' AND RetailerCode='"+retailerCode+"'"; 
      long retailerUpdate = dbAdapter.updateRecordsInDB("WMRetailer", retailerValues, strWhereField, null); 
      System.out.println("---retailerUpdate--" + retailerUpdate); 
     } else{ 
      Toast.makeText(SalesActivityGroup.group.getParent(),"You have already made invoice today.You can't make call Loast " ,Toast.LENGTH_SHORT).show(); 
     } 

     dbAdapter.close(); 
     return visitStatus; 
    } 

    public HashMap<String,CallLostReason> getAllCallLoast(){ 
     DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this); 
     dbAdapter.openDataBase(); 

     String query = "SELECT CallLostReasonCode,Description ,Status FROM WMCallLostReason WHERE Status = '1' "; 
     ArrayList<?> stringList = dbAdapter.selectRecordsFromDBList(query, null); 

     dbAdapter.close(); 
     HashMap<String,CallLostReason> wmCallLoast = new HashMap<String,CallLostReason>(); 
     for (int i = 0; i < stringList.size(); i++) { 

      ArrayList<?> arrayList = (ArrayList<?>) stringList.get(i); 
      ArrayList<?> list = arrayList; 
      CallLostReason lostReason = new CallLostReason(); 
      lostReason.setDescription((String) list.get(1)); 
      lostReason.setCallLostReasonCode((String) list.get(0)); 
      lostReason.setStatus((String) list.get(2)); 
      wmCallLoast.put((String) list.get(1),lostReason); 
     } 
     return wmCallLoast; 
    } 

} 

は同様に私が持っている:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/wallpaper"> 
    <TableLayout android:layout_height="wrap_content" android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_marginBottom="50dp" android:layout_weight="1"> 
     <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content"> 
      <TextView android:text="Call Lost" android:layout_marginLeft="100dp" android:textColor="@color/darkGreen" android:layout_marginBottom="20dp" android:textStyle="bold" android:textSize="20dp" android:gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/thcall"></TextView> 
     </TableRow> 


     <TableRow android:id="@+id/tableRow1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp"> 
      <TextView android:id="@+id/calostRetailer" android:layout_height="wrap_content" android:text="Retiler Name :" android:layout_weight="0.8" android:layout_width="0dp" ></TextView> 
      <TextView android:text="Retiler Name" android:layout_height="wrap_content" android:id="@+id/txtcalostRetailer" android:layout_weight="0.8" android:layout_width="55dp" ></TextView> 
     </TableRow> 

     <TableRow android:id="@+id/tableRow2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp"> 
      <TextView android:text="Call Lost Reason" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.4" android:id="@+id/txtcalostRetailer" ></TextView> 
      <Spinner android:layout_height="wrap_content" android:id="@+id/cal_lost_reason" android:layout_weight="0.8" android:layout_width="150dp"></Spinner> 
     </TableRow> 


     <TableRow android:id="@+id/tableRow3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp"> 
      <CheckBox android:text="Cancael" android:id="@+id/chkCallLost" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> 
     </TableRow> 

    </TableLayout> 


    <LinearLayout android:id="@+id/headerInDis" 
      android:background="#000000" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent"> 

      <Button android:layout_width="wrap_content" 
        android:text="Cancel" 
        android:background="@drawable/btn_yellow" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="235dp" 
        android:id="@+id/callLostCancel" 
        android:textColor="#FFFFFF" 
        > 
      </Button> 

      <Button android:layout_width="wrap_content" 
        android:text="Ok" 
        android:background="@drawable/btn_yellow" 
        android:layout_height="wrap_content" 
        android:textColor="#FFFFFF" 
        android:id="@+id/callLostDOk" 
        > 
      </Button> 
     </LinearLayout> 
</LinearLayout> 

は、マニフェストファイルでは、私はこれが私の活動のクラスである

 <application android:configChanges="orientation|keyboardHidden" android:label="Vertusel" android:icon="@drawable/virtusel64" android:allowClearUserData="true" android:debuggable="true" android:enabled="true" > 
     <activity android:name=".AndroidAppXontTabActivity" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    <activity android:name=".sales.CallLostActivity" android:configChanges="orientation|keyboardHidden"></activity> 
    ..... 

のように宣言しました。

私の質問は、ユーザーが携帯電話をランドスケープに変更してアプリケーションを終了するときです。

私のコードで何が間違っているのか教えてください。

+2

あなたのアクティビティからいくつかのコードを与えてください... – Jovan

+0

あなたのアクティビティの一部のコードが、再描画時にクラッシュする可能性があります。 –

+0

私のコードを更新しました... – Kartheepan

答えて

1

は、以下を使用してマニフェストファイルを交換してみてください:

<application 
    android:allowClearUserData="true" 
    android:configChanges="orientation|keyboardHidden" 
    android:debuggable="true" 
    android:enabled="true" 
    android:icon="@drawable/virtusel64" 
    android:label="Vertusel" > 

    <activity android:name=".AndroidAppXontTabActivity" 
     android:configChanges="keyboardHidden|orientation|screenSize" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".sales.CallLostActivity" 
     android:configChanges="keyboardHidden|orientation|screenSize" > 
    </activity> 

それはあなたを助けますように。

関連する問題