我有一個問題,從ListAdapter中啓動一個新的AsyncTask。但首先,這裏是的情況:從ListAdapter中啓動一個AsyncTask
我有一個活動,包含一個ListView。此ListView通過適配器填充
ReservationAdapter adapter = new ReservationAdapter(self, (List<Reservation>) msg.obj);
reservationListView.setAdapter(adapter);
ReservationAdapter具有自定義列表項(2個字符串+ 1個按鈕)。下面的getView() - 方法:
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View view = convertView;
if (convertView == null) {
view = layoutInflater.inflate(R.layout.list_item_reservation, null);
}
ImageButton button = (ImageButton) view.findViewById(R.id.removeButton);
LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayout);
TextView title = (TextView) view.findViewById(R.id.title);
TextView subTitle = (TextView) view.findViewById(R.id.subTitle);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Here I need to start the AsyncTask
}
});
// Here I'm filling the Labels... (not important)
return view;
}
我知道,如何啓動任務出的正常活動的聽衆,但我如何啓動它從onClicklistener在適配器類?
我不明白這個問題嗎?你可以在任何你想要的地方開始異步任務。究竟是什麼讓你煩惱? – JanBo