2016-06-17 17 views
0

私はStackOverflowを初めて使うので、間違いがあれば謝罪します。私が抱えている問題は、私がAndroid AppでGooglePlacesAutocomplete Activityを使用するたびに、アドレスを入力するとtextviews.Whileが両方とも満たされます。私が「自分の出発点」をクリックするたびにその方法で動作するようにしたいplacesautocompleteアクティビティに入力すると、入力した住所は「あなたの出発点」のテキストビューでのみ満たされ、「あなたの目的地」と同様になります。GooglePlacesAutocompleteは、あなたの出発地と目的地の両方のテキストビューに同じアドレスを返します。

それでは、また、Datetextviewで「日付 - 年 - 年」の代わりに「今日」または「明日」を取得する方法についても説明します。

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

    eet1 = (TextView) findViewById(R.id.eet1); 
    eet2 = (TextView) findViewById(R.id.eet2); 

    eet1.setOnClickListener(this); 
    eet2.setOnClickListener(this); 

    // Open the autocomplete activity when the TextView is clicked. 
    TextView openTextview = (TextView) findViewById(R.id.eet1); 
    assert openTextview != null; 
    openTextview.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (v == eet1) 
      openAutocompleteActivity(); 
     } 

    }); 


    // Open the autocomplete activity when the TextView is clicked. 
    TextView openTextView = (TextView) findViewById(R.id.eet2); 
    assert openTextView != null; 
    openTextView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (v == eet2) 
      openAutocompleteActivity(); 
     } 

    }); 

    timetext = (TextView) findViewById(R.id.timetext); 
    datetext = (TextView) findViewById(R.id.datetext); 

    timetext.setOnClickListener(this); 
    datetext.setOnClickListener(this); 

} 

protected void openAutocompleteActivity() { 
    try { 
     // The autocomplete activity requires Google Play Services to be available. The intent 
     // builder checks this and throws an exception if it is not the case. 
     Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) 
       .build(this); 
     startActivityForResult(intent, 1); 
    } catch (GooglePlayServicesRepairableException e) { 
     // Indicates that Google Play Services is either not installed or not up to date. Prompt 
     // the user to correct the issue. 
     GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), 
       0 /* requestCode */).show(); 
    } catch (GooglePlayServicesNotAvailableException e) { 
     // Indicates that Google Play Services is not available and the problem is not easily 
     // resolvable. 
     String message = "Google Play Services is not available: " + 
       GoogleApiAvailability.getInstance().getErrorString(e.errorCode); 

     Log.e(TAG, message); 
     Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); 
    } 
} 

/** 
* Called after the autocomplete activity has finished to return its result. 
*/ 
@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    // Check that the result was from the autocomplete widget. 
    if (requestCode == REQUEST_CODE_AUTOCOMPLETE) { 
     if (resultCode == RESULT_OK) { 
      // Get the user's selected place from the Intent. 
      Place place = PlaceAutocomplete.getPlace(this, data); 
      Log.e(TAG, "Place: " + place.getAddress()); 

      assert findViewById(R.id.eet1) != null; 
      ((TextView) findViewById(R.id.eet1)) 
        .setText(place.getName() + ",\n" + 
          place.getAddress()); 


     } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { 
      Status status = PlaceAutocomplete.getStatus(this, data); 
      Log.e(TAG, "Error: Status = " + status.toString()); 
     } else if (resultCode == RESULT_CANCELED) { 
      // Indicates that the activity closed before a selection was made. For example if 
      // the user pressed the back button. 
     } 
    } 

    // Check that the result was from the autocomplete widget. 
    if (requestCode == REQUEST_CODE_AUTOCOMPLETE) { 
     if (resultCode == RESULT_OK) { 
      // Get the user's selected place from the Intent. 
      Place place = PlaceAutocomplete.getPlace(this, data); 
      Log.e(TAG, "Place: " + place.getAddress()); 

      assert findViewById(R.id.eet2) != null; 
      ((TextView) findViewById(R.id.eet2)) 
        .setText(place.getName() + ",\n" + 
          place.getAddress()); 


     } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { 
      Status status = PlaceAutocomplete.getStatus(this, data); 
      Log.e(TAG, "Error: Status = " + status.toString()); 
     } else if (resultCode == RESULT_CANCELED) { 
      // Indicates that the activity closed before a selection was made. For example if 
      // the user pressed the back button. 
     } 
    } 
} 

@Override 
public void onClick(View v) { 
    if (v == datetext) { 

     // Process to get Current Date 
     final Calendar c = Calendar.getInstance(); 
     mYear = c.get(Calendar.YEAR); 
     mMonth = c.get(Calendar.MONTH); 
     mDay = c.get(Calendar.DAY_OF_MONTH); 

     // Launch Date Picker Dialog 
     DatePickerDialog dpd = new DatePickerDialog(this, 
       new DatePickerDialog.OnDateSetListener() { 

        @Override 
        public void onDateSet(DatePicker view, int year, 
              int monthOfYear, int dayOfMonth) { 
         // Display Selected date in textbox 
         datetext.setText(dayOfMonth + "-" 
           + (monthOfYear + 1) + "-" + year); 

        } 
       }, mYear, mMonth, mDay); 
     dpd.show(); 
    } 
    if (v == timetext) { 

     // Process to get Current Time 
     final Calendar c = Calendar.getInstance(); 
     mHour = c.get(Calendar.HOUR_OF_DAY); 
     mMinute = c.get(Calendar.MINUTE); 

     // Launch Time Picker Dialog 
     TimePickerDialog tpd = new TimePickerDialog(this, 
       new TimePickerDialog.OnTimeSetListener() { 

        @Override 
        public void onTimeSet(TimePicker view, int hourOfDay, 
              int minute) { 
         // Display Selected time in textbox 
         timetext.setText(hourOfDay + ":" + minute); 
        } 
       }, mHour, mMinute, false); 
     tpd.show(); 
    } 
} 
+0

スクリーンショットをアップロードできません! – Shubhendra

+0

問題が解決しました。 – Shubhendra

答えて

0

あなたはあなたのためonActivityResult方法での問題を抱えて、あなたは両方のTextViewのためのコードを書きました。したがって、ユーザーが場所を選択すると、両方のTextViewが同時に塗りつぶされます。

+0

問題は既に解決されていますが、私は質問を閉じるのを忘れていたので、寛大な努力をして受け入れます。 – Shubhendra

関連する問題