Oto kod mojej klasy Adaptera
package com.example.lukasz.test;
import android.content.Context;
import android.support.annotation.ColorRes;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;
import java.util.ArrayList;
import java.util.List;
/**
* Created by lukasz on 23.09.15.
*/
@EBean
public class CitiesNamesAdapter extends BaseAdapter {
public ArrayList<String> citiesNames;
public CitiesNamesAdapter() {
}
@Bean
GetCityName findCity;
@RootContext
Context context;
@ColorRes
int mint;
@AfterInject
void initAdapter() {
citiesNames = findCity.getAll();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CityItemView cityItemView;
if (convertView == null) {
cityItemView = new CityItemView_(context);
} else {
cityItemView = (CityItemView_) convertView;
}
if (position % 2 == 0) {
parent.setBackgroundColor(mint);
}
cityItemView.bind(getItem(position));
return cityItemView;
}
@Override
public int getCount() {
return citiesNames.size();
}
@Override
public String getItem(int position) {
return citiesNames.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
I teraz kod klasy laczacej dane z widokiem
package com.example.lukasz.test;
import android.content.Context;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EView;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
/**
* Created by lukasz on 23.09.15.
*/
@EViewGroup(R.layout.city_item)
public class CityItemView extends LinearLayout {
@ViewById
TextView cityName;
public CityItemView(Context context) {
super(context);
}
public void bind(String name) {
this.cityName.setText(name);
}
}
I problem jest taki ze w momencie wywolania metody bind(String name) do TextView cityName nie zostala jeszcze przypisana zadna referencja. I nie wiem co z tym zrobic, bo jesli dodam adnotacje @AfterViews na metoda bind to mi pokazuje ze nie moze to byc metoda z parametrami. Przy pisaniu tych klas wzorowalem sie na tym https://github.com/excilys/androidannotations/wiki/adapters-and-lists i moja klasa CityItemView to klasa PersonItemVIew stamtad,ale jednak u mnie to nie dziala, chociaz wydaje mi sie ze zrobione jest to tak jak tam pokazano.
Z gory dzieki za wszelkie sugestie