0

私は1つの編集テキストがあるアンドロイドアプリを開発しています...最初の編集テキストはユーザーの名を与えることです..ユーザーの名などの文字が入力されます...そして文字ごとに異なる値が与えられます...これらすべての値を追加する方法についての私の質問....?

各文字を個別に取得する方法...そして配列に入れ、そのすべての値を追加します

    public class MainActivity extends Activity {

    Button btn1;
    EditText et1, et2, et3, et4, et5, et6;
    Spinner sp1,sp2,sp3;
    TextView txt1,txt2,txt3,txt4,txt5,txt6,txt7,txt8,txt9,txt10;
    String month,day,year;
    int sum;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main);

    }

    public void calc(View v)
    {

        EditText et1 = (EditText) findViewById (R.id.editText1);
        /*TextView txt1 = (TextView) findViewById ( R.id.textView88);*/
        sum=getSum(et1.getText().toString());
        Intent i=new Intent(MainActivity.this, result.class);
        i.putExtra("name", sum);
        startActivity(i);

        /*txt1.setText(sum + "");*/


    }

    private int getSum(String text) 
    {
        // TODO Auto-generated method stub
        int sum = 0;
        char[] name = new char[text.length()];
        name = text.toCharArray();

        for(int i=0; i<text.length(); i++)
        {
            sum += value( name[i] );
        }
        while (sum>9)
        {
            sum = findDigitSum(sum);
        }

        return sum;
    }



    public int findDigitSum(int n) 
    {
        int sum = 0;
        while (n != 0) 
        {
            sum += n % 10;
            n = n / 10;
        }
        return sum;
    }
    private int value(char a) {
        // TODO Auto-generated method stub
        switch(a) {
        case 'A': 
           return 1;
        case 'B':
           return 2;
        case 'C':
           return 3;
        case 'D': 
            return 4;
         case 'E':
            return 5;
         case 'F':
            return 6; 
         case 'G': 
             return 7;
          case 'H':
             return 8;
          case 'I':
             return 9;
          case 'J': 
              return 1;
          case 'K':
              return 2;
           case 'L':
              return 3;
           case 'M': 
               return 4;
            case 'N':
               return 5;
            case 'O':
               return 6; 
            case 'P': 
                return 7;
             case 'Q':
                return 8;
             case 'R':
                return 9;
             case 'S': 
                 return 1;
             case 'T':
                 return 2;
              case 'U':
                 return 3;
              case 'V': 
                  return 4;
               case 'W':
                  return 5;
               case 'X':
                  return 6; 
               case 'Y': 
                   return 7;
                case 'Z':
                   return 8;
                 default:
            return 0;
    }





}
}

2 番目のアクティビティ result.java

public class result extends Activity {

    TextView txt2;
    /*private Intent getIntent;*/



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result_xm);
        TextView txt2 = (TextView) findViewById(R.id.textView2);
        txt2.setText(getIntent().getStringExtra("name"));
        /*Intent iin= getIntent();
        Bundle b = iin.getExtras();
        if(b!=null)
        {
            String name = getIntent.getStringExtra("name");
            txt2.setText(name);
        }*/
    }

}

Logcat の詳細

08-26 20:25:47.579: E/Trace(1873): error opening trace file: No such file or directory (2)
08-26 20:25:49.179: D/dalvikvm(1873): GC_CONCURRENT freed 39K, 6% free 2788K/2948K, paused 19ms+89ms, total 195ms
08-26 20:25:50.311: I/Choreographer(1873): Skipped 33 frames!  The application may be doing too much work on its main thread.
08-26 20:25:50.579: D/gralloc_goldfish(1873): Emulator without GPU emulation detected.
08-26 20:27:38.388: D/dalvikvm(1873): GC_CONCURRENT freed 125K, 8% free 3049K/3296K, paused 81ms+21ms, total 257ms
08-26 20:27:40.869: I/Choreographer(1873): Skipped 30 frames!  The application may be doing too much work on its main thread.
08-26 20:27:42.209: D/AndroidRuntime(1873): Shutting down VM
08-26 20:27:42.229: W/dalvikvm(1873): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-26 20:27:42.349: E/AndroidRuntime(1873): FATAL EXCEPTION: main
08-26 20:27:42.349: E/AndroidRuntime(1873): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.numerology/com.example.numerology.result}: java.lang.NullPointerException
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.os.Looper.loop(Looper.java:137)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at java.lang.reflect.Method.invoke(Method.java:511)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at dalvik.system.NativeStart.main(Native Method)
08-26 20:27:42.349: E/AndroidRuntime(1873): Caused by: java.lang.NullPointerException
08-26 20:27:42.349: E/AndroidRuntime(1873):     at com.example.numerology.result.onCreate(result.java:19)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.Activity.performCreate(Activity.java:5104)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-26 20:27:42.349: E/AndroidRuntime(1873):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-26 20:27:42.349: E/AndroidRuntime(1873):     ... 11 more
4

2 に答える 2

0

あなたが望むのはAutocomplete Text Viewだと思います。オートコンプリート テキスト ビューの詳細な実装については、リンクを参照してください。

于 2013-08-26T09:24:18.970 に答える