I have a project to manage if the football freestyler landed a trick, like TVShowTime app but with tricks. I have a Custom Adapter for the Listview and four arrays of Strings, I don't know how to save the checkboxes states for each trick.
The checkbox state was configured inside the CustomAdapter0.
Other problem that I'm having is that the checkboxes needs to be pressed twice to change, after you pressed twice if works ok. I have no idea how to fix this.
ListView and checkboxes
CustomAdapter
public class CustomAdapter0 extends BaseAdapter {
public CustomAdapter0(String[] tricks, Context context) {
this.tricks = tricks;
this.context = context;
}
private String[] tricks;
private Context context;
private boolean isClicked;
private LayoutInflater layoutInflater;
@Override
public int getCount() {
return tricks.length;
}
@Override
public Object getItem(int i) {
return i;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
View row = convertView;
if(convertView == null){
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.custom_listview_tricks, null);
}
TextView textView = row.findViewById(R.id.name_xml);
final ImageButton imageButton = row.findViewById(R.id.unmastered_xml);
textView.setText(tricks[i]);
imageButton.setBackgroundResource(R.drawable.unmastered);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isClicked) {
imageButton.setBackgroundResource(R.drawable.mastered);
} else {
imageButton.setBackgroundResource(R.drawable.unmastered);
}
isClicked = !isClicked;
}
});
return row;
}
}
TricksActivity
public class TricksActivity extends AppCompatActivity {
private String[] lower = {
"ATW - Around the World",
"HTW - Hop the World",
"Crossover",
"Crossover 360",
"Simple Crossover",
"Reverse Crossover",
"KATW - Knee Around the World",
"KHTW - Knee Hop the World",
"Toe Bounce",
"Reverse Toe Bounce",
"Air Jester",
"ATL - Around the Leg",
"Hell Juggles",
"AATW - Abbas Around the World",
"HATW - Half Around the World",
"TATW - Touzani Around the World",
"MATW - Mitchy Around the World",
"ATATW - AlternateTouzani Around the World",
"AMATW - Alternate Mitchy Around the World",
"HMATW - Homie Mitchy Around the World",
"HTATW - Homie Touzani Around the World",
"KAATW - Knee Abbas Around the World",
"KMATW - Knee Mitchy Around the World",
"KTATW - Knee Touzani Around the World",
"LEBATW - Lebioda Around the World",
"LATW - Lemmens Around the World",
"MAATW - Mitchy Abbas Around the World",
"RATW - Ratinho Around the World",
"ATL - Around the Leg",
"360 ATW",
"Clipper",
"JATOW - Joshua Around the Oppositive World",
"Sagami Aroudn the World",
"YATW - Yosuke Around the World",
"Timo ATW",
"Knee Timo ATW",
"Air Jester",
"Eclipse",
"Half New Shit",
"ALATW - Alternate Lemmens Around the World",
"BATW - Beck Around the World",
"HJATW - Homie Jay Around the World",
"HMAATW - Homie Mitchy Abbas Around the World",
"HTAATW - Homie Touzani Abbas Around the World",
"KAMATW - Knee Alternate Mitchy Around the World",
"KATATW - Knee Alternate Touzani Around the World",
"KMAATW - Knee Mitchy Alternate Around the World",
"LAATW - Lemmens Abbas Around the World",
"LMATW - Lemmens Mitchy Around the World",
"LTATW - Lemmens Touzani Around the World",
"Magellan",
"New Shit",
"Palle Trick",
"Reverse Palle Trick",
"Toe Stall",
"Hell Stall",
"Knee Stall",
"Hell Juggles",
"Spin Magic",
"MichRyc Move",
"AHMATW - Alternate Homie Mitchy Around the World",
"AHTATW - Alternate Homie Touzani Around the World",
"ALMATW - Alternate Lemmens Mitchy Around the World",
"KLAATW - Knee Lemmens Abbas Around the World",
"SATW - Skora Around the World",
"Skora Move",
"RSATW - Reverse Skora Around the World",
" HTLATW - Homie Touzani Lemmens Around the World",
"SZATW - Szymo Around The World",
"EATW - Eldo Around the World",
"SKATW - Skala Around the World",
"ZATW - Zegan Around the World",
"K3EATW - K3vin Eldo Around the World",
"SKMATW - Skala Mitchy Around the World",
"EMATW - Eldo Mitchy Around the World",
"AEATW - Alternate Eldo Around the World",
"PATW - Palle Around the World",
"PMATW - Palle Mitchy Around the World",
"APATW - Alternate Palle Around the World"
};
private String[] upper = {
"Head Stall",
"Top Head Stall",
"Side Head Stall",
"Shoulder Stall",
"Neck Stall",
"360",
"Chest Stall",
"ATM - Around The Moon",
"Carousel",
"Pavel Roll",
"LIP Stall",
"Arm Roll",
"Nose Stall",
"Neck Flick",
"LATM - Luki Around the Moon",
};
private String[] sitDown = {
"Shin Stall",
"Sole Stall",
"Abdullah",
"Sole Juggle",
"Shin ATW",
"Dimetto"
};
private String[] combosFamosos= {
"CNK NT Combo",
"Skóra NT Combo",
"Palle Combo",
"Palle Combo 2"
};
private ImageView imageView;
private int codigo;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tricks);
Intent intent = getIntent();
codigo = intent.getIntExtra("codigo", 0);
//Toast.makeText(this, ""+codigo, Toast.LENGTH_SHORT).show();
listView = findViewById(R.id.listview_xml);
if (codigo == 0){
CustomAdapter0 customAdapter0 = new CustomAdapter0(lower, TricksActivity.this);
listView.setAdapter(customAdapter0);
}if (codigo == 1){
CustomAdapter0 customAdapter0 = new CustomAdapter0(upper, TricksActivity.this);
listView.setAdapter(customAdapter0);
}if (codigo == 2){
CustomAdapter0 customAdapter0 = new CustomAdapter0(sitDown, TricksActivity.this);
listView.setAdapter(customAdapter0);
}if (codigo == 3){
CustomAdapter0 customAdapter0 = new CustomAdapter0(combosFamosos, TricksActivity.this);
listView.setAdapter(customAdapter0);
}if (codigo == 4){
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getApplicationContext(), VideoActivity.class);
if(codigo == 0){
//Toast.makeText(TricksActivity.this, ""+lower[i], Toast.LENGTH_SHORT).show();
intent.putExtra("trick", lower[i]);
}
if(codigo == 1){
//Toast.makeText(TricksActivity.this, ""+upper[i], Toast.LENGTH_SHORT).show();
intent.putExtra("trick", upper[i]);
}
if(codigo == 2){
//Toast.makeText(TricksActivity.this, ""+sitDown[i], Toast.LENGTH_SHORT).show();
intent.putExtra("trick", sitDown[i]);
}
if(codigo == 3){
//Toast.makeText(TricksActivity.this, ""+combosFamosos[i], Toast.LENGTH_SHORT).show();
intent.putExtra("trick", combosFamosos[i]);
}
startActivity(intent);
}
});
}
}