2017-12-12 13 views
0

내가 만들고있는 앱의 일부입니다. 옵션 메뉴에서 버튼을 선택했습니다. 해당 버튼을 클릭하면 사용자 정의 대화 상자가 열립니다. 새로운 대화 상자를 열려면 해당 사용자 지정 대화 상자에 단추가 있어야하지만, 어떤 이유로 내 방법으로 인해 응용 프로그램이 중단됩니다. 어떤 도움이라도 대단히 감사 할 것입니다.사용자 지정 대화 상자에서 단추를 클릭하여 대화 상자를 만들려면 어떻게해야합니까?

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

    //Copy and paste this line to onClick methods regarding the edit text dialog 
    // textentry = (EditText)findViewById(R.id.entrybox); 


    // Button year = (Button)findViewById(R.id.Year); 



} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.options, menu); 
    return true; 
} 

//Dialog Box for selecting View books in Options Menu 
public Dialog ViewBookOptions() { 
    AlertDialog.Builder builder = 
      new AlertDialog.Builder(this); 
    LayoutInflater inflater = this.getLayoutInflater(); 
    View v = inflater.inflate(R.layout.view_books, null); 
    builder.setView(v); 
    final AlertDialog dialog = builder.create(); 
    return dialog; 



} 

//Dialog boxes for selecting Year, Author, or Title in the ViewBook Dialog Box 

public Dialog ViewByYear(){ 
    AlertDialog.Builder builder = 
      new AlertDialog.Builder(this); 
    LayoutInflater inflater = this.getLayoutInflater(); 
    View v = inflater.inflate(R.layout.text_entry, null); 
    builder.setView(v); 
    final EditText entrybox = (EditText) v.findViewById(R.id.entrybox); 
    builder.setPositiveButton("Ok", 
      new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialogInterface, int i) { 
        String entry = entrybox.getText().toString().toLowerCase(); 
        //This is Where You Will Populate The ListView With Database Stuff 
       } 
      }); 
    builder.setNegativeButton(
      "Cancel", 
      new DialogInterface.OnClickListener() { 
         public void onClick(
           DialogInterface dialog, int id) { 
          dialog.cancel(); 
         } 
        }); 
    AlertDialog dialog = builder.create(); 
    return dialog; 

} 

      //Quick Toast for checking stuff 
       public void toast(String string){ 
       Toast.makeText(this, string, Toast.LENGTH_SHORT).show(); 
     } 
     //All of my button OnClick Methods 
     public void allbooks(View view){ 
     toast("You clicked All books"); 
     } 
      public void year(View view){ 
    toast("Dialog should open and EditText should change hint text"); 
    EditText textentry = (EditText)findViewById(R.id.entrybox); 
     textentry.setHint("Enter the Year of the Book(s)"); 
     Dialog dialog = ViewByYear(); 
    dialog.show(); 
     } 


     // The Options Menu 
     @Override 
     public boolean 
     onOptionsItemSelected 
     (MenuItem item) { 
      switch (item.getItemId()) { 
     case R.id.option1: 
      //Change to View Book Options 
      Dialog dialog = ViewBookOptions(); 
      dialog.show(); 
      return true; 
     case R.id.option2: 

      return true; 
     case R.id.option3: 

      return true; 
     case R.id.option4: 

      return true; 
     case R.id.option5: 

      return true; 
     default: 
      return super.onOptionsItemSelected(item); 
      } 
     } 

이것이 내 활동 코드입니다. 두 번째 대화 상자가 만들어지기 전에 오류가 첫 번째 대화 상자와 관련이 있다고 생각하지만이 대화 상자를 수정하는 방법은 확실하지 않습니다. 대화 상자가 다른 인스턴스의 다른 단추에서 호출되기 때문입니다.

+0

치명적인 오류 로그를 게시 할 수 있습니까? –

+1

'DialogFragment'를 사용하는 것이 좋습니다. 회전 등의 모든 작업을 처리 할 수 ​​있습니다. 예를 들어 문서를 확인하려면 https://developer.android.com/reference/android/app/DialogFragment.html – Micer

+0

지금 확인해보세요. 정말 고마워! – John

답변