2
When finished creating a listFragment and calling it in main the apk terminates giving the error below:
Here is my Listfragment:
ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
SimpleAdapter adapter;
String[] atividades = new String[]{"item1", "item2", "item3"};
int[] imageId = {
R.drawable.imagem1,
R.drawable.image2,
R.drawable.image3,
};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
HashMap<String, String> map = new HashMap<String, String>();
for (int i = 0; i < atividades.length; i++) {
map = new HashMap<String, String>();
map.put("atividade", atividades[i]);
map.put("imagem", Integer.toString(imageId[i]));
data.add(map);
}
String[] from = {"atividade", "imageId"};
int[] to = {R.id.txt, R.id.img};
adapter = new SimpleAdapter(getActivity(), data, R.id.listView, from, to);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
and my main class:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
FirstFragment fragment = new FirstFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();