First thing, this code works. Essentially I check for the position clicked in a listview with an if statement, and then I run another check to compare drawables in order to display the proper text (So if a user clicks on an image of a frog, I will populate the EditText field with the text "Frog"). One major issue I have had is that the image is a random image, which ultimately led me to this monster piece of code.
if(position==0) {
if (username.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.image06).getConstantState())) {
Toast.makeText(ChatRoom2.this, "Key", Toast.LENGTH_LONG)
.show();
String next = "<font color='#13b602'>@Key </font>";
editText.append(Html.fromHtml(next));
editText.setSelection(editText.getText().length());
} if (username.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.image03).getConstantState())) {
String next = "<font color='#13b602'>@BlueCube</font>";
editText.setText(Html.fromHtml(next));
editText.setSelection(editText.getText().length());
}
}
That is the check for the first position, and only two nested ifs for two images - I have 30 images to check, so each position would have 30 if statements, and 10 positions. I have a feeling that my solution to this issue is quite poor, as I would need to create 500+ lines of code for this to simply work. Is there any way to create a separate class that just holds the if statements?