I'm trying to call another Fragment
when I click on list item but it doesn't work, I'm using slider menu and the items of ListView
are options inside the slider menu. What am I doing wrong?
public class MenuNetimoveis_Fragments extends ListFragment {
private ListView listView;
String[] itensMenu = new String[] {
" Imóveis no mapa",
"Favoritos",
"Agências",
"Dicas para Alugar",
"Alugar meu imóvel",
"Sobre"
};
int[] imagens = new int[]{
R.drawable.map_marker,
R.drawable.star,
R.drawable.house,
R.drawable.coffee,
R.drawable.pricetag,
R.drawable.pricetag
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.list, null);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ImageView tv = new ImageView(getActivity());
Drawable dw = getResources().getDrawable(R.drawable.menu_netimoveis_locacao);
tv.setImageDrawable(dw);
getListView().addHeaderView(tv);
crateListView();
}
private void crateListView(){
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<6;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("txt", itensMenu[i]);
hm.put("imagens", Integer.toString(imagens[i]) );
aList.add(hm);
}
String[] from = { "txt","imagens" };
int[] to = { R.id.text,R.id.imagemview};
SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.list_row, from, to);
setListAdapter(adapter);
}
@Override
public void onListItemClick(ListView lv, View v, int position, long id) {
Fragment newContent = null;
switch (position) {
case 0:
newContent = new Menu_DicasParaAlugar();
break;
case 1:
break;
}
if (newContent != null)
switchFragment(newContent);
}
// the meat of switching the above fragment
private void switchFragment(Fragment fragment) {
if (getActivity() == null)
return;
if (getActivity() instanceof FragmentChangeActivity) {
FragmentChangeActivity fca = (FragmentChangeActivity) getActivity();
fca.switchContent(fragment);
}
}
}