0

while i am searching for examples to make list of answers in expandable list i found code which use 4 java classes and one xml with expand list but not use xml for parent and child and i want to change text color and check box color

XML

<Spinner
    android:id="@+id/coursescomplaint"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    android:layout_gravity="center"
    android:spinnerMode="dialog"
    style="@style/spinner_style"/>

<ExpandableListView
    android:id="@+id/expandcomplaintcourse"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@color/Button"
    android:text="Submit"
    android:layout_gravity="center"/>

JAVA

    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.ExpandableListView;
    import android.widget.Spinner;
    import android.widget.Toast;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    public class Complaint extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

private static List<Answers> questions;
private ExpandableListView expandableListView;
private AnswersAdabter adapter;

private int lastExpandedPosition = -1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_complaint);

    LoadQuestions();
    expandableListView = (ExpandableListView)findViewById(R.id.expandcomplaintcourse);
    adapter = new AnswersAdabter(this, questions);

    expandableListView.setAdapter(adapter);

    // The choice mode has been moved from list view to adapter in order
    // to not extend the class ExpansibleListView
    adapter.setChoiceMode(AnswersAdabter.CHOICE_MODE_SINGLE_PER_GROUP);

    // Handle the click when the user clicks an any child
    expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {
            adapter.setClicked(groupPosition, childPosition);
            return false;
        }
    });

    expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            if (lastExpandedPosition != -1 && groupPosition != lastExpandedPosition) {
                expandableListView.collapseGroup(lastExpandedPosition);
            }
            lastExpandedPosition = groupPosition;
        }
    });


    // Spinner element
    Spinner spinner = (Spinner) findViewById(R.id.coursescomplaint);

    // Spinner click listener
    spinner.setOnItemSelectedListener(this);

    // Spinner Drop down elements
    List<String> categories = new ArrayList<String>();
    categories.add("Course1");
    categories.add("Course2");
    categories.add("Course3");

    // Creating adapter for spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner, categories);

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    spinner.setAdapter(dataAdapter);

}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // On selecting a spinner item
    String item = parent.getItemAtPosition(position).toString();

    // Showing selected spinner item
    Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();

}

public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}
private void LoadQuestions() {
    questions = new ArrayList<Answers>();

    ArrayList<String> citiesAustralia = new ArrayList<String>(
            Arrays.asList("Brisbane", "Hobart", "Melbourne", "Sydney"));
    questions.add(new Answers("Australia", citiesAustralia));

    ArrayList<String> citiesChina = new ArrayList<String>(
            Arrays.asList("Beijing", "Chuzhou", "Dongguan", "Shangzhou"));
    questions.add(new Answers("China", citiesChina));

    ArrayList<String> citiesIndia = new ArrayList<String>(
            Arrays.asList("Bombay", "Calcutta", "Delhi", "Madras"));
    questions.add(new Answers("India", citiesIndia));

    ArrayList<String> citiesNewZealand = new ArrayList<String>(
            Arrays.asList("Auckland", "Christchurch", "Wellington"));
    questions.add(new Answers("New Zealand", citiesNewZealand));

    ArrayList<String> citiesRussia = new ArrayList<String>(
            Arrays.asList("Moscow", "Kursk", "Novosibirsk", "Saint Petersburg"));
    questions.add(new Answers("Russia", citiesRussia));
}
}
Mina Nabil
  • 13
  • 1
  • 4
  • Welcome to StackOverflow. It is always good to indicate what you have tried and what programming problems you have encountered - copying and pasting the code without any explanation as to what the code is meant to accomplish is not helpful. Please look at [how to ask good question](http://stackoverflow.com/help/how-to-ask) and improve your question. – ishmaelMakitla May 17 '16 at 21:47
  • it might be helpfull for you. check my answer http://stackoverflow.com/questions/37249781/load-data-into-an-expandablelistview/37250461#37250461 – Pramod mishra May 18 '16 at 03:49
  • sorry but this not helpful for me i want to change text color and background of header and child programmatically because i have only one xml which contain expand list only as i wrote above @Pramodmishra – Mina Nabil May 18 '16 at 13:05
  • ( https://github.com/jiahaoliuliu/ExpandableListViewWithChoice ) i used this code on my project and i don't know how can i change text color or change check box style – Mina Nabil May 18 '16 at 14:04
  • In which case you want to change header and child back or text color what your scenario. – Pramod mishra May 18 '16 at 14:07
  • i don't understand you – Mina Nabil May 18 '16 at 15:12

0 Answers0