有人可以帮助我,我想从IF转移到sqlite [英] Can someone help me I want to transfer from IF to sqlite
本文介绍了有人可以帮助我,我想从IF转移到sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个程序我想把它从(IF)转换为sqlite
i have this program i want to convert it from ( IF ) to sqlite
package com.app.army.tab;
/**
* Created by army on 8/31/2017.
*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Tab4Weight extends Fragment {
EditText firstNumber;
EditText secondNumber;
TextView addResult;
Button btnAdd;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab4weight, container, false);
firstNumber = (EditText)view.findViewById(R.id.txtNumber1);
secondNumber = (EditText)view.findViewById(R.id.txtNumber2);
addResult = (TextView)view.findViewById(R.id.txtResult);
btnAdd = (Button)view.findViewById(R.id.btnAdd);
btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!TextUtils.isEmpty(firstNumber.getText().toString())&&!TextUtils.isEmpty(secondNumber.getText().toString())){
String value1= firstNumber.getText().toString();
String value2= secondNumber.getText().toString();
int a=Integer.parseInt((value1));
int b=Integer.parseInt((value2));
int sum= getCoordinates(a,b);
Toast.makeText(getActivity(),"Weight in Kg: " +
String.valueOf(sum),Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getActivity(), "value is empty", Toast.LENGTH_SHORT).show();
}
}
private int getCoordinates (int coordA, int coordB){
int results = 0;
if (coordA < 7000 && coordB < 30 && coordB > -45)
{
results = 7400;
}
else {
if
(coordA==8000 && coordB ==30)
{
results = 7100;
}
else {
if
(coordA==9000 && coordB ==30)
{
results = 6850;
}
else {
if
(coordA==9000 && coordB ==20)
{
results = 7100;
}
else {
if
(coordA==9000 && coordB ==10)
{
results = 7350;
}
else {
if
(coordA==10000 && coordB ==30)
{
results = 6850;
}
else {
if
(coordA==10000 && coordB ==20)
{
results = 6800;
}
else {
if
(coordA==10000 && coordB ==10)
{
results = 7100;
}
else {
if
(coordA==10000 && coordB ==0)
{
results = 7350;
}
else {
if
(coordA==11000 && coordB ==20)
{
results = 6550;
}
else {
if
(coordA==11000 && coordB ==10)
{
results = 6800;
}
else {
if
(coordA==11000 && coordB ==0)
{
results = 7080;
}
else {
if
(coordA==11000 && coordB == -10)
{
results = 7360;
}
else {
if
(coordA==12000 && coordB ==20)
{
results = 6380;
}
else {
if
(coordA==12000 && coordB ==10)
{
results = 6510;
}
else {
if
(coordA==12000 && coordB ==0)
{
results = 6800;
}
else {
if
(coordA==12000 && coordB == -10)
{
results = 7100;
}
else {
if
(coordA==12000 && coordB == -20)
{
results = 7350;
}
else {
if
(coordA==13000 && coordB ==20)
{
results = 6010;
}
else {
if
(coordA==13000 && coordB ==10)
{
results = 6260;
}
else {
if
(coordA==13000 && coordB ==0)
{
results = 6510;
}
else {
if
(coordA==13000 && coordB == -10)
{
results = 6800;
}
else {
if
(coordA==13000 && coordB == -20)
{
results = 7080;
}
else {
if
(coordA==13000 && coordB == -30)
{
results = 7400;
}
else {
if
(coordA==14000 && coordB ==20)
{
results = 5780;
}
else {
if
(coordA==14000 && coordB ==15)
{
results = 5900;
}
else {
if
(coordA==14000 && coordB ==10)
{
results = 6000;
}
else {
if
(coordA==14000 && coordB ==0)
{
results = 6250;
}
else {
if
(coordA==14000 && coordB == -10)
{
results = 6510;
}
else {
if
(coordA==14000 && coordB == -20)
{
results = 6800;
}
else {
if
(coordA==14000 && coordB ==-30)
{
results = 7100;
}
else {
if
(coordA==15000 && coordB ==20)
{
results = 5550;
}
else {
if
(coordA==15000 && coordB ==15)
{
results = 5250;
}
else {
if
(coordA==15000 && coordB ==10)
{
results = 5260;
}
else {
if
(coordA==15000 && coordB ==0)
{
results = 6000;
}
else {
if
(coordA==15000 && coordB == -10)
{
results = 6250;
}
else {
if
(coordA==15000 && coordB == -20)
{
results = 6510;
}
else {
if
(coordA==15000 && coordB == -30)
{
results = 6800;
}
else {
if
(coordA==15000 && coordB == -40)
{
results = 7100;
}
else {
if
(coordA==15000 && coordB == -45)
{
results = 7290;
}
else {
if
(coordA==16000 && coordB ==15)
{
results = 5400;
}
else {
if
(coordA==16000 && coordB ==10)
{
results = 5520;
}
else {
if
(coordA==16000 && coordB ==0)
{
results = 5760;
}
else {
if
(coordA==16000 && coordB == -10)
{
results = 6000;
}
else {
if
(coordA==16000 && coordB == -20)
{
results = 6280;
}
else {
if
(coordA==16000 && coordB == -30)
{
results = 6510;
}
else {
if
(coordA==16000 && coordB == -40)
{
results = 6820;
}
else {
if
(coordA==16000 && coordB == -45)
{
results = 7000;
}
else {
if
(coordA==17000 && coordB ==15)
{
results = 5200;
}
else {
if
(coordA==17000 && coordB ==10)
{
results = 5300;
}
else {
if
(coordA==17000 && coordB ==0)
{
results = 5510;
}
else {
if
(coordA==17000 && coordB == -10)
{
results = 5780;
}
else {
if
(coordA==17000 && coordB == -20)
{
results = 6000;
}
else {
if
(coordA==17000 && coordB == -30)
{
results = 6280;
}
else {
if
(coordA==17000 && coordB == -40)
{
results = 6550;
}
else {
if
(coordA==17000 && coordB == -45)
{
results = 6710;
}
else {
if
(coordA==18000 && coordB ==10)
{
results = 5100;
}
else {
if
(coordA==18000 && coordB ==0)
{
results = 5300;
}
else {
if
(coordA==18000 && coordB == -10)
{
results = 5520;
}
else {
if
(coordA==18000 && coordB == -20)
{
results = 5750;
}
else {
if
(coordA==18000 && coordB == -30)
{
results = 6000;
}
else {
if
(coordA==18000 && coordB == -40)
{
results = 6290;
}
else {
if
(coordA==18000 && coordB == -45)
{
results = 6450;
}
else {
if
(coordA==19000 && coordB ==10)
{
results = 4900;
}
else {
if
(coordA==19000 && coordB ==0)
{
results = 5080;
}
else {
if
(coordA==19000 && coordB == -10)
{
results = 5800;
}
else {
if
(coordA==19000 && coordB == -20)
{
results = 5500;
}
else {
if
(coordA==19000 && coordB == -30)
{
results = 5250;
}
else {
if
(coordA==19000 && coordB == -40)
{
results = 5780;
}
else {
if
(coordA==19000 && coordB == -45)
{
results = 5900;
}
else {
if
(coordA==20000 && coordB ==10)
{
results = 4700;
}
else {
if
(coordA==20000 && coordB ==0)
{
results = 4890;
}
else {
if
(coordA==20000 && coordB == -10)
{
results = 5080;
}
else {
if
(coordA==20000 && coordB == -20)
{
results = 5300;
}
else {
if
(coordA==20000 && coordB == -30)
{
results = 5520;
}
else {
if
(coordA==20000 && coordB == -40)
{
results = 5780;
}
else {
if
(coordA==20000 && coordB == -45)
{
results = 5900;
}
else {
if
(coordA==8000 && coordB ==20)
{
results = 7380;
}
else {
if
(coordA==8000 && coordB <20)
{
results = 7400;
}
else {
if
(coordA==9000 && coordB <10)
{
results = 7400;
}
else {
if
(coordA==10000 && coordB <0)
{
results = 7400;
}
else {
if
(coordA==11000 && coordB < -10)
{
results = 7400;
}
else {
if
(coordA==12000 && coordB < -20)
{
results = 7400;
}
else {
if
(coordA==13000 && coordB < -30)
{
results = 7400;
}
else {
if
(coordA==14000 && coordB < -40 )
{
results = 7400;
}
else {
if
(coordA==0 && coordB ==0)
{
results = 0;
}
else {
if
(coordA==0 && coordB ==0)
{
results = 7400;
}
else {
if
(coordA==0 && coordB ==0)
{
results = 7400;
}
else {
if
(coordA==0 && coordB ==0)
{
results = 7400;
}
else {
if
(coordA==0 && coordB ==0)
{
results = 7400;
}
else {
if
(coordA==0 && coordB ==0)
{
results = 7400;
}
else {
Toast.makeText(getActivity(),"Error data Input" ,Toast.LENGTH_LONG).show();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return results;
}
});
firstNumber.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
int jumlah = Integer.parseInt(firstNumber.getText().toString());
if( firstNumber.getText().toString().equals("")||jumlah > 10001 && jumlah < 10999) {
firstNumber.setText("11000");
return;
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 11001 && jumlah < 11999) {
firstNumber.setText("12000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 12001 && jumlah < 12999) {
firstNumber.setText("13000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 13001 && jumlah < 13999) {
firstNumber.setText("14000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 14001 && jumlah < 14999) {
firstNumber.setText("15000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 15001 && jumlah < 15999) {
firstNumber.setText("16000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 16001 && jumlah < 16999) {
firstNumber.setText("17000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 17001 && jumlah < 17999) {
firstNumber.setText("18000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 18001 && jumlah < 18999) {
firstNumber.setText("19000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 19001 && jumlah < 19999) {
firstNumber.setText("20000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("0");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("0");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("0");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("0");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("0");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("0");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("7000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 7001 && jumlah < 7999) {
firstNumber.setText("8000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 8001 && jumlah < 8999) {
firstNumber.setText("9000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 9001 && jumlah < 9999) {
firstNumber.setText("10000");
}
else {
if (firstNumber.getText().toString().equals("") || jumlah > 0 && jumlah < 0) {
firstNumber.setText("0");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
});
return view;
}
}
What I have tried:
i want to transfer to database from IF
What I have tried:
i want to transfer to database from IF
推荐答案
Do yourself a favour, and throw that code in the bin!
Have you seen how deeply nested and unreadable that code is? You haven’t even got the indentation right, so it’s pretty much impossible to work out what is going on. Forget \"converting it to SqLite\" - refactor it so it is in some way readable first. And if you think that doing the same thing twenty or more times in a row is a good idea, you really need to rethink your design...
Do yourself a favour, and throw that code in the bin!
Have you seen how deeply nested and unreadable that code is? You haven't even got the indentation right, so it's pretty much impossible to work out what is going on. Forget "converting it to SqLite" - refactor it so it is in some way readable first. And if you think that doing the same thing twenty or more times in a row is a good idea, you really need to rethink your design...
The complexity metrics of this code reaches 360 while a \"usable\" complexity level should be lower than 50 I think ... AS OG suggests, the code must be refactored first to reduce the complexity, before doing anything else.
The complexity metrics of this code reaches 360 while a "usable" complexity level should be lower than 50 I think ... AS OG suggests, the code must be refactored first to reduce the complexity, before doing anything else.
这篇关于有人可以帮助我,我想从IF转移到sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文