내 목표는 목록 상자를 체크 상자를 사용하도록 설정하면 목록의 끝으로 밀어 넣는 것입니다. 내 목록 항목이 "작업"개체입니다.Android - 목록보기에 동적으로 개체 추가
ListView lv=this.getListView();
int size=lv.getCount();
Myarrayadapter adapter = new Myarrayadapter(this,getTasks());
lv.setAdapter(adapter);
lv.invalidateViews();
private List<Task> getTasks() {
List<Task> list = new ArrayList<Task>();
for(int k=0;k<taskname.length;k++)//taskname is an array of tasknames
{
list.add(new Task(taskname[k],status[k]));
return list;
}
Myarrayadapter 클래스가 목표 below.my 표시되어, 체크 박스가 enabled.If 예 여부를 확인 일부 변경 (텍스트 색상 및 단추 텍스트)을하고 마지막 위치로이 변경된 뷰를 이동하는 것입니다.
public class Myarrayadapter extends ArrayAdapter<Task> {
private final Activity context;
private final List<Task> list;
public Myarrayadapter(Activity context, List<Task> list) {
super(context, R.layout.list_item, list);
this.context = context;
this.list=list;
}
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_item, null, true);
final TextView text = (TextView) rowView.findViewById(R.id.label);
CheckBox checkbox = (CheckBox) rowView.findViewById(R.id.cb);
final Button btnChild = (Button) rowView.findViewById(R.id.directions);
text.setText(list.get(position).getName());
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked)
{
text.setTextColor(Color.parseColor("#468765"));
btnChild.setText("Revert");
Task taskItem= list.get(position);
list.remove(position);
list.add(taskItem);
}
}});
return rowView;
}
정확한 목록 항목을 옮기지 않았습니다.
미리 감사드립니다. !!!!
당신은 당신의 ArrayAdapter와 일부 메서드를 재정의해야
실패했습니다. 다른 솔루션 – siraj
@siraj :'notifyDataSetChanged();가 Adapter에 속해 있기 때문에 변수가 없거나'Myarrayadapter.this.notifyDataSetChanged();'가없는 경우에만'notifyDataSetChanged();'를 호출해야합니다) –
@AdilSoomro yes adil 당신은 그가 notifyDataSetChanged()의 호출을 할 필요가 있습니다 어댑터 자체에서 그래서 그는 단지 notifyDataSetChanged() 호출해야한다고 생각합니다 –