0
我的問題與我的customadapter擴展simplecursoradapter。問題是,在一個Listener裏面我想從另一個視圖獲取數據。我可以使用checkedtextview,但我不認爲它看起來不錯。從另一個視圖訪問數據在另一個視圖內setOnCheckedListener
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_of_ingredients, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.box = (CheckBox) convertView.findViewById(R.id.box);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
這裏是內部setOnCheckedListener棘手的部分我想訪問文本中的TextView我holder.name但我不知道該如何使它發揮作用。
holder.box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//array to store check/not checked
checkBoxState.set(position, isChecked);
}
});
這裏是其餘的代碼probaly不需要,但我無論如何增加它。
cursor.moveToPosition(position);
holder.name.setText(cursor.getString(cursor
.getColumnIndex(DatabaseHelper.COLUMN_NAME)));
holder.box.setChecked(checkBoxState.get(position));
return convertView;
}
你試過adapter.getView(position,null,listview)這將返回視圖,並伴隨它的屬性 –