I have a code of adding tasks by clicking the button and choose colors.
I want that after adding a task to change its contents with long click opens dialog with edittext.
how can i do that?
sorry for my bad english!
LinearLayout container;
EditText inputText;
TextView txt;
RadioGroup colorPick;
int checkedColor;
//Counter
int i=1;
int id=1;
//Colors
int red = Color.parseColor("#EF9A9A");
int blue = Color.parseColor("#90CAF9");
int white = Color.parseColor("#FFFFFF");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputText = (EditText)findViewById(R.id.inputText);
container=(LinearLayout)findViewById(R.id.container);
colorPick=(RadioGroup)findViewById(R.id.colorPick);
colorPick.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.colorBlue:
checkedColor=blue;
break;
case R.id.colorRed:
checkedColor=red;
break;
case R.id.colorWhite:
checkedColor=white;
break;
default:
checkedColor=white;
}
}
});
}
public void add(View v){
final String input=inputText.getText().toString();
txt = new TextView(this);
if(input.matches("")){
inputText.setBackgroundColor(-65536);
}else{
txt.setHeight(50);
txt.setText(i+". "+input);
txt.setBackgroundColor(checkedColor);
i++;
container.addView(txt);
colorPick.clearCheck();
inputText.setText("");
//Add a edit option
txt.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
id=txt.getId();
dialogCustom();
return false;
}
});
}
}
public void remove(View v){
container.removeAllViews();
}
public void removeEditColor(View v){
inputText.setBackgroundColor(0x00000000);
}
private void dialogCustom(){
AlertDialog.Builder editTxtDialog = new AlertDialog.Builder(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
EditText input1 = new EditText(this);
editTxtDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
input1.setHint("Change the task..");
layout.addView(input1);
editTxtDialog.setView(layout);
editTxtDialog.show();
}