Dans mon application, j'utilise Navigation Drawer avec ListView en Fragment. Et j'ai implémenté avec succès la vue de liste dans Fragment. mais maintenant je veux faire ajouter une image dans cette liste.Comment le faire. Vous avez besoin d'exempleAjouter des images dans ListView en Fragment - Navigation Drawer
Ceci est mon fichier Vegall.java
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Vegall extends Fragment {
private ListView lv;
private static String[] vegalllist = {"Vegetables1", "Vegetables2"};
public static Vegall newInstance()
{
Vegall vegall =new Vegall();
return vegall;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View rootView=inflater.inflate(R.layout.vegall, null);
lv = (ListView) rootView.findViewById(R.id.vegall_lv);
lv.setAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, vegalllist));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l){
//Toast.makeText(getActivity(), vegcat[i], Toast.LENGTH_SHORT).show();
selectItem(i);
}
});
return rootView;
}
private void selectItem(int i){
Fragment newFragment;
FragmentTransaction transaction = getFragmentManager().beginTransaction();
switch (i){
case 0:
newFragment = new Vegetables1();
transaction.replace(R.id.containerID, newFragment);
transaction.addToBackStack(null);
transaction.commit();
break;
case 1:
Intent intent = new Intent(getActivity(), Vegetables2.class);
startActivity(intent);
break;
}
}
@Override
public String toString(){
return "Home";
}
}
Ceci est mon Vegall.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/vegall_lv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>