Bonjour,Android - événement setOnItemClickListener de ListView ne fonctionne pas dans Fragment
J'ai un problème avec l'événement setOnItemClickListener
d'un ListView
intérieur d'un fragment qui n'a jamais tiré.
Voici le code de l'élément dans listView
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dip" >
<ImageView
android:id="@+id/url_foto"
android:layout_width="100dip"
android:layout_height="100dip"
android:src="@drawable/stub"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/url_foto"
android:orientation="vertical"
android:paddingLeft="10sp" >
<TextView
android:id="@+id/nome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true" />
<TextView
android:id="@+id/cognome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true" />
Voici le code XML de la liste (qui comprend également un edittext avec quelques auditeurs):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/cerca_il_prof_edit_search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="search" />
<ListView
android:id="@+id/cerca_il_prof_list_result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="true"
android:focusable="true" />
et enfin le fragment qui contient l'événement qui ne se déclenche pas:
public class CercaIlProfFragment extends Fragment {
private DbAdapter dbHelper;
private Cursor cursor;
private Context ctx;
List<Professore> listProf;
private static final String TAG = "CercaIlProf - ";
private EditText string_search;
private ListView listViewProf;
int textlength = 0;
/**
* The fragment argument representing the section number for this fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.cerca_il_prof, container, false);
ctx = getActivity();
listProf = new ArrayList<Professore>();
string_search = (EditText) rootView.findViewById(R.id.cerca_il_prof_edit_search);
Date currDate = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(currDate);
calendar.add(Calendar.MONTH, 1);
// get all prof
getAllProf();
listViewProf = (ListView) rootView.findViewById(R.id.cerca_il_prof_list_result);
ProfessoreListAdapterWithCache professoreListAdapterWithCache = new ProfessoreListAdapterWithCache(ctx,
R.layout.cerca_il_prof_list_result_item, listProf, this.getActivity());
listViewProf.setAdapter(professoreListAdapterWithCache);
listViewProf.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "Click ListItem Number " + position, Toast.LENGTH_LONG).show();
}
});
listViewProf.setEnabled(true);
string_search.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Toast.makeText(getActivity(), "Click ListItem Number ", Toast.LENGTH_LONG).show();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//do stuff
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
//do stuff
});
return rootView;
}
quelqu'un peut me aider ?? s'il vous plaît
Merci d'avance.
Cordialement.
Giuseppe
Comment pourriez-vous avoir un problème si votre fragment n'est jamais tiré? – Blackbelt