Tôi đang cố gắng tùy chỉnh thanh công cụ hành động android cho thứ gì đó giống như ứng dụng dòng điện của google. Về cơ bản, chỉ có 'phụ đề' nên phản ánh những gì tôi chọn từ spinner trong khi 'tiêu đề' vẫn giữ nguyên. Tôi hiểu rằng cần phải tạo một spinner tùy chỉnh và tôi phải ghi đè phương thức getView()
và getDropDownView()
. Nhưng tôi rất bối rối ở đây về cách ghi đè các phương thức này đúng cách. Có thể một số xin vui lòng thúc đẩy tôi đi đúng hướng. Tôi hy vọng tôi đã làm rõ câu hỏi của tôi.Tùy biến spinner của thanh tác vụ
the image screenshot http://androidcowboy.com/wp-content/uploads/2012/12/google-currents-3a.jpg
Đưa ra dưới đây là mã của tôi.
public class CustomSpinnerAdapter extends BaseAdapter {
private LayoutInflater inflater;
private final Context context;
private final String[] dropDown;
private final String mainText;
private final String subText;
public CustomSpinnerAdapter(Context context,
String mainText, String subText,String[] dropDown) {
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mainText=mainText;
this.subText=subText;
this.context = context;
this.dropDown=dropDown;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View actionBarView = inflater.inflate(R.layout.custom_spinner, null);
TextView textView = (TextView) actionBarView
.findViewById(R.id.custom_spinner_textview);
textView.setText(mainText);
return actionBarView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View dropDownView = inflater.inflate(R.layout.custom_spinner, null);
TextView dropDownTextView = (TextView) dropDownView
.findViewById(R.id.custom_spinner_dropdown_textview);
dropDownTextView.setText(dropDown[position]);
return dropDownView;
}
}
Objectlayers là gì? – ajay