可扩展列表样式更改?

时间:2016-05-17 21:30:34

标签: android eclipse android-studio expandablelistview expandable

虽然我正在搜索可扩展列表中的答案列表的示例,但我找到了使用4个java类和一个带有扩展列表的xml但不使用xml用于父级和子级的代码,我想更改文本颜色和复选框颜色

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));
}
}

0 个答案:

没有答案
相关问题