This code is very long, and you need a separate method. How can I implement it?
I have 6 (x2) imageview buttons and 6 edittext.
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.imageViewPlusSubEdit1:
if(editTextInputNameSubEdit1.getText().toString().trim().length() == 0)
{
Toast.makeText(this, "Empty text!", Toast.LENGTH_SHORT).show();
}
else if(items1.size() > 23)
{
Toast.makeText(this, "Too many elements!", Toast.LENGTH_SHORT).show();
}
else
{
items1.add(editTextInputNameSubEdit1.getText().toString());
adapterList1.notifyDataSetChanged();
editTextInputNameSubEdit1.setText("");
}
break;
case R.id.imageViewMinusSubEdit1:
SparseBooleanArray checkedItemPositions = listViewSubEdit1.getCheckedItemPositions();
int itemCount = listViewSubEdit1.getCount();
for(int i = itemCount - 1; i >= 0; i--)
{
if(checkedItemPositions.get(i))
{
adapterList1.remove(items1.get(i));
}
}
checkedItemPositions.clear();
adapterList1.notifyDataSetChanged();
break;
case R.id.imageViewPlusSubEdit2:
if(editTextInputNameSubEdit2.getText().toString().trim().length() == 0)
{
Toast.makeText(this, "Empty text!", Toast.LENGTH_SHORT).show();
}
else if(items2.size() > 23)
{
Toast.makeText(this, "Too many elements!", Toast.LENGTH_SHORT).show();
}
else
{
items2.add(editTextInputNameSubEdit2.getText().toString());
adapterList2.notifyDataSetChanged();
editTextInputNameSubEdit2.setText("");
}
break;
case R.id.imageViewMinusSubEdit2:
SparseBooleanArray checkedItemPositions2 = listViewSubEdit2.getCheckedItemPositions();
int itemCount2 = listViewSubEdit2.getCount();
for(int i = itemCount2 - 1; i >= 0; i--)
{
if(checkedItemPositions2.get(i))
{
adapterList2.remove(items2.get(i));
}
}
checkedItemPositions2.clear();
adapterList2.notifyDataSetChanged();
break;
case R.id.imageViewPlusSubEdit3:
if(editTextInputNameSubEdit3.getText().toString().trim().length() == 0)
{
Toast.makeText(this, "Empty text!", Toast.LENGTH_SHORT).show();
}
else if(items3.size() > 23)
{
Toast.makeText(this, "Too many elements!", Toast.LENGTH_SHORT).show();
}
else
{
items3.add(editTextInputNameSubEdit3.getText().toString());
adapterList3.notifyDataSetChanged();
editTextInputNameSubEdit3.setText("");
}
break;
case R.id.imageViewMinusSubEdit3:
SparseBooleanArray checkedItemPositions3 = listViewSubEdit3.getCheckedItemPositions();
int itemCount3 = listViewSubEdit3.getCount();
for(int i = itemCount3 - 1; i >= 0; i--)
{
if(checkedItemPositions3.get(i))
{
adapterList3.remove(items3.get(i));
}
}
checkedItemPositions3.clear();
adapterList3.notifyDataSetChanged();
break;
case R.id.imageViewPlusSubEdit4:
if(editTextInputNameSubEdit4.getText().toString().trim().length() == 0)
{
Toast.makeText(this, "Empty text!", Toast.LENGTH_SHORT).show();
}
else if(items4.size() > 23)
{
Toast.makeText(this, "Too many elements!", Toast.LENGTH_SHORT).show();
}
else
{
items4.add(editTextInputNameSubEdit4.getText().toString());
adapterList4.notifyDataSetChanged();
editTextInputNameSubEdit4.setText("");
}
break;
case R.id.imageViewMinusSubEdit4:
SparseBooleanArray checkedItemPositions4 = listViewSubEdit4.getCheckedItemPositions();
int itemCount4 = listViewSubEdit4.getCount();
for(int i = itemCount4 - 1; i >= 0; i--)
{
if(checkedItemPositions4.get(i))
{
adapterList4.remove(items4.get(i));
}
}
checkedItemPositions4.clear();
adapterList4.notifyDataSetChanged();
break;
case R.id.imageViewPlusSubEdit5:
if(editTextInputNameSubEdit5.getText().toString().trim().length() == 0)
{
Toast.makeText(this, "Empty text!", Toast.LENGTH_SHORT).show();
}
else if(items5.size() > 23)
{
Toast.makeText(this, "Too many elements!", Toast.LENGTH_SHORT).show();
}
else
{
items5.add(editTextInputNameSubEdit5.getText().toString());
adapterList5.notifyDataSetChanged();
editTextInputNameSubEdit5.setText("");
}
break;
case R.id.imageViewMinusSubEdit5:
SparseBooleanArray checkedItemPositions5 = listViewSubEdit5.getCheckedItemPositions();
int itemCount5 = listViewSubEdit5.getCount();
for(int i = itemCount5 - 1; i >= 0; i--)
{
if(checkedItemPositions5.get(i))
{
adapterList5.remove(items5.get(i));
}
}
checkedItemPositions5.clear();
adapterList5.notifyDataSetChanged();
break;
case R.id.imageViewPlusSubEdit6:
if(editTextInputNameSubEdit6.getText().toString().trim().length() == 0)
{
Toast.makeText(this, "Empty text!", Toast.LENGTH_SHORT).show();
}
else if(items6.size() > 23)
{
Toast.makeText(this, "Too many elements!", Toast.LENGTH_SHORT).show();
}
else
{
items6.add(editTextInputNameSubEdit6.getText().toString());
adapterList6.notifyDataSetChanged();
editTextInputNameSubEdit6.setText("");
}
break;
case R.id.imageViewMinusSubEdit6:
SparseBooleanArray checkedItemPositions6 = listViewSubEdit6.getCheckedItemPositions();
int itemCount6 = listViewSubEdit6.getCount();
for(int i = itemCount6 - 1; i >= 0; i--)
{
if(checkedItemPositions6.get(i))
{
adapterList6.remove(items6.get(i));
}
}
checkedItemPositions6.clear();
adapterList6.notifyDataSetChanged();
break;
}