내가 안드로이드에 어댑터를 만들어 다시 초기화 : 스피너 다시 초기화 그래서 목록 또는 EditView에서 액세스에서의 getView가 다시 호출 스크롤 할 때 때때로는 목록보기의 안드로이드 스피너 때로는
public class PointVerificationAdapter extends BaseAdapter {
List<PointVerification> mObjects;
Context mContext;
LayoutInflater mInflater;
Dao<ChoixPointVerification, Integer> mChoixPointVerificationDao;
HashMap<Integer, ReponsePointVerification> mReponses;
public PointVerificationAdapter(Context context,
Dao<ChoixPointVerification, Integer> choixPointVerificationDao,
List<PointVerification> ListePointsVerification,
HashMap<Integer, ReponsePointVerification> listeReponsesPointsVerification) {
mInflater = LayoutInflater.from(context);
this.mContext = context;
this.mObjects = ListePointsVerification;
this.mChoixPointVerificationDao = choixPointVerificationDao;
this.mReponses = listeReponsesPointsVerification;
}
@Override
public int getCount() {
return mObjects.size();
}
@Override
public PointVerification getItem(int position) {
return mObjects.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (null == convertView) {
row = mInflater.inflate(R.layout.intervention_reponses_list, null);
} else {
row = convertView;
}
// affichage du nom du point de vérification
TextView tv = (TextView) row.findViewById(R.id.tvNom);
tv.setText(getItem(position).nom);
Integer idChoixPointVerification = null;
Integer idPointVerification = getItem(position).id;
if (mReponses != null && mReponses.containsKey(idPointVerification)) {
// affichage du commentaire
if (mReponses.get(idPointVerification).commentaire != null)
{
EditText edCommentaire = (EditText) row.findViewById(R.id.edCommentaire);
edCommentaire.setText(mReponses.get(idPointVerification).commentaire);
}
idChoixPointVerification = mReponses.get(idPointVerification).idChoixPointVerification;
}
// affichage de la liste déroulante
Spinner spi = (Spinner) row.findViewById(R.id.spiListeChoix);
ChoixPointVerificationDal choixPointVerificationDal = new ChoixPointVerificationDal();
List<ChoixPointVerification> listeChoixPointVerification;
try {
listeChoixPointVerification = choixPointVerificationDal
.GetByIdPointVerification(mChoixPointVerificationDao,
getItem(position).id);
List<String> pointVerifications = new ArrayList<String>();
for(ChoixPointVerification choixPointVerification: listeChoixPointVerification)
{
pointVerifications.add(choixPointVerification.nom);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_dropdown_item,
pointVerifications);
spi.setAdapter(adapter);
} catch (SQLException e) {
e.printStackTrace();
}
return row;
}
및 나는 사용자 선택을 잃는다. 이것에 대한 해결책이 있습니까?
편집
아니라 내 느낌의 getView 정말 매우 자주 전화해서 내가 그 기능에 간다 스피너 매번 REINIT하지 말아야한다는 것입니다. 그러나 이것이이 코드의 첫 번째 실행인지 어떻게 알 수 있습니까? 나는 ID에게 위치가이
spi.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
varPosition = position;
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
같이가 someting로 선택하지만 난 그것이 좋은 방법이라고 생각하지 않습니다 가게 ... 내가 원하는 경우 :(
편집 2
했다 OnItemClickListener와 스피너를 만들 수있는 기술이 순간 내가 무엇 그 :.?
public class PointVerificationAdapter extends BaseAdapter {
List<PointVerification> mObjects;
Context mContext;
LayoutInflater mInflater;
Dao<ChoixPointVerification, Integer> mChoixPointVerificationDao;
HashMap<Integer, ReponsePointVerification> mReponses;
Integer mPositionSelectionne;
public PointVerificationAdapter(
Context context,
Dao<ChoixPointVerification, Integer> choixPointVerificationDao,
List<PointVerification> ListePointsVerification,
HashMap<Integer, ReponsePointVerification> listeReponsesPointsVerification) {
mInflater = LayoutInflater.from(context);
this.mContext = context;
this.mObjects = ListePointsVerification;
this.mChoixPointVerificationDao = choixPointVerificationDao;
this.mReponses = listeReponsesPointsVerification;
}
@Override
public int getCount() {
return mObjects.size();
}
@Override
public PointVerification getItem(int position) {
return mObjects.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (null == convertView) {
row = mInflater.inflate(R.layout.intervention_reponses_list, null);
} else {
row = convertView;
}
// affichage du nom du point de vérification
TextView tv = (TextView) row.findViewById(R.id.tvNom);
tv.setText(getItem(position).nom);
Integer idPointVerification = getItem(position).id;
if (mReponses != null && mReponses.containsKey(idPointVerification)) {
// affichage du commentaire
if (mReponses.get(idPointVerification).commentaire != null) {
EditText edCommentaire = (EditText) row
.findViewById(R.id.edCommentaire);
edCommentaire
.setText(mReponses.get(idPointVerification).commentaire);
}
}
// affichage de la liste déroulante
Spinner spi = (Spinner) row.findViewById(R.id.spiListeChoix);
spi.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
View row = mInflater.inflate(R.layout.intervention_reponses_list, null);
ChoixPointVerificationDal choixPointVerificationDal = new ChoixPointVerificationDal();
List<ChoixPointVerification> listeChoixPointVerification;
try {
listeChoixPointVerification = choixPointVerificationDal
.GetByIdPointVerification(mChoixPointVerificationDao,
getItem(position).id);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
android.R.layout.simple_spinner_dropdown_item,
pointVerifications);
spi.setAdapter(adapter);
} catch (SQLException e) {
e.printStackTrace();
}
}
});
return row;
}
에드 그것은 3
목록보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/lstPointsVerification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</ListView>
</LinearLayout>
그리고 목록보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvNom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/ListePrincipal"
/>
<Spinner
android:id="@+id/spiListeChoix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<EditText
android:id="@+id/edCommentaire"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/ListePrincipal"
/>
</LinearLayout>
내 목표의 각 라인에 대한 목록보기가 포함 된 작업의 레이아웃은 verificate하는 점의 목록을 작성하기 위해 단지이다 사용자가 그는 약 20 줄의 검증을해야합니다. 각 행에는 레이블, 차이 선택 항목이있는 회 전자 및 주석 필드가 들어 있습니다. 그러면 각 줄마다 각 대답을 검색해야합니다.
getView() 내부에 스피너를 넣으면 올바른 작업을 수행하고 있습니까? OnItemClick과 같은 것을 원하고 회 전자를 다시 만들 수 있습니까? –
글쎄 아마 그걸하는 법을 배울 것입니다 ... tk you –
다음은 getView()의 호출 수에 대한 다른 게시물의 답변입니다. AdapterView getView는 AdapterView에 뷰가 필요할 때만 호출됩니다 . getView가 호출되는 빈도 또는 횟수에 대한 가정을해서는 안됩니다. getView가 수행해야하는 유일한 작업은 필요한보기를 가능한 빨리 리턴하는 것입니다. 여기에서 가져온 http://stackoverflow.com/questions/3287563/doubts-with-base-adapter-class-and-its-functionality. ---- 왜 코드의 첫 번째 실행을 확인하고 싶습니까? 아마도 당신은 어댑터를 작성한 후에 itemclicks를 사용하여 결함에 대해 더 많은 통찰력을 제공해야합니다. –