我只想让TextView
转入EditText
的输入,但它不起作用。这也是一个自定义数组适配器,而不是Activity
,如果这有任何区别。我也让它工作了,我改变了AndroidManifest.xml
中的方向然后我将其更改回默认值,EditText
输入不再更改TextView
。
我甚至使用VCS本地历史回到我以前的代码我不知道发生了什么。这是我的代码。
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)
编辑上面创建的文本oncreate并在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);
}
});
你可以在对话框中保留一个按钮,或者你可以继续自己的方式,但需要