2016-12-20 62 views
0

我只想將TextView變成EditText的輸入,但它不起作用。此外,這是在一個自定義陣列適配器不是Activity,如果這有所作爲。此外,我有它的工作,我改變了方向AndroidManifest.xml然後我改回它的默認和EditText輸入不再改變TextView如何從alertDialog中將editText輸入設置爲textView

我甚至使用VCS本地歷史回到我以前的代碼我不知道發生了什麼。這是我的代碼。上面的OnCreate

class CustomAdapter extends ArrayAdapter{ 

    public CustomAdapter(Context context, ArrayList choreText) { 
     super(context, R.layout.custon_listview_row, choreText); 
    } 

    @NonNull 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     LayoutInflater myInflater = LayoutInflater.from(getContext()); 
     View customView = myInflater.inflate(R.layout.custon_listview_row, parent, false); 
     ImageButton imageButton = (ImageButton) customView.findViewById(R.id.imageButton_ID); 
     final TextView textView = (TextView) customView.findViewById(R.id.textView_ID); 
     final EditText input = new EditText(getContext()); 
     final AlertDialog OptionDialog = new AlertDialog.Builder(getContext()).create(); 

     // makes textView clickable 
     textView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       //what happens when textView is clicked 

       //final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 
       // put aler dialog box logic here 
       OptionDialog.setTitle("Enter new chore"); 
       OptionDialog.setView(input); 
       input.setInputType(InputType.TYPE_CLASS_TEXT); 
       input.setImeOptions(EditorInfo.IME_ACTION_DONE); 
       //checks if "Done" button on soft keyboard is clicked 
       input.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
        @Override 
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
         if(actionId==EditorInfo.IME_ACTION_DONE){ 
          //what happens when "Done" is clicked 
          textView.setText(input.getText().toString()); 
          OptionDialog.dismiss(); 

         } 
         return false; 
        } 
       }); 

       OptionDialog.show(); 
      } 
     }); 

     imageButton.setImageResource(R.drawable.clock); 

     return customView; 
    } 
} 
+0

「它不工作」它有多遠?它是崩潰還是什麼? –

+0

它全部工作只是textView不會更改爲用戶輸入。它保持不變。 –

+0

然後檢查是否(actionId == EditorInfo.IME_ACTION_DONE){//}天氣這個塊執行放在這裏面的第一行日誌,看看它是否被稱爲 –

回答

0

編輯文本initailised和索引裏面的onCreate()

EditText editText; 
onCreate() 
editText = (EditText) findViewById(R.id.edit_message); 

//調用對話框並繼續

Button saveButton = (Button)dialog.findViewById(R.id.saveButton); 
    saveButton.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View arg0) { 
      String text = ((EditText)dialog.findViewById(R.id.text)).getText().toString(); 
      editText.setText(text); 
     } 
    }); 

U可以保持一個按鈕,在對話框中和或你可以繼續與你的方式本身,但需要

相關問題