當單擊列表視圖的圖像和文本視圖時,我需要從一個活動的列表視圖切換到一個片段。從活動到片段的通信
我有一個適配器:
public class AdapterResultList extends BaseAdapter {
Context contexto;
List<DirectoryData> ListaDirectorio;
Fragment fragment = null;
public AdapterResultList(Context contexto, List<DirectoryData> listaDirectorio) {
this.contexto = contexto;
ListaDirectorio = listaDirectorio;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View vista = convertView;
LayoutInflater inflate = LayoutInflater.from(contexto);
vista = inflate.inflate(R.layout.details_list_directory,null);
TextView professionalName = (TextView) vista.findViewById(R.id.doctors_name);
ImageView imagen1 = (ImageView) vista.findViewById(R.id.subcategory_image);
professionalName.setText(ListaDirectorio.get(position).getProfessionalName().toString());
imagen1.setImageResource(ListaDirectorio.get(position).getImagen1());
return vista;
}
}
而且在活動:
public class ResultSearch extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result_search);
listaProf = (ListView) findViewById(R.id.list_profesionals);
ListaDr = new ArrayList<DirectoryData>();
ListaDr.add(new DirectoryData("Dr. Pedro Perez", R.drawable.successright));
ListaDr.add(new DirectoryData("Dr. Juan Rodriguez", R.drawable.searchbanner));
AdapterResultList miadaptador = new AdapterResultList(getApplicationContext(), ListaDr);
listaProf.setAdapter(miadaptador);
}
}
時點擊的ImageView或TextView的我只需要去DoctorsDetailsFragment
。我不需要發送數據。
使用點擊監聽器,適配器和適配器 – param
致電片段是的,我想,但怎麼稱呼從適配器的片段?對不起,我在這個新的。 – jeanf