I got a way out!
public class TopRatedFragment extends Fragment { private String[] mNames = { "Fabian", "Carlos", "Alex", "Andrea", "Karla", "Freddy", "Lazaro", "Hector", "Carolina", "Edwin", "Jhon", "Edelmira", "Andres" }; private String[] mAnimals = { "Perro", "Gato", "Oveja", "Elefante", "Pez", "Nicuro", "Bocachico", "Chucha", "Curie", "Raton", "Aguila", "Leon", "Jirafa" }; int[] flags = new int[]{ R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher }; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>(); for(int i=0;i<10;i++){ HashMap<String, String> hm = new HashMap<String,String>(); hm.put("txt", "App Name : " + mNames[i]); hm.put("cur","creator : " + mAnimals[i]); hm.put("flag", Integer.toString(flags[i]) ); aList.add(hm); } String[] from = { "flag","txt","cur" }; int[] to = { R.id.flag,R.id.txt,R.id.cur,R.id.textView2}; View v = inflater.inflate(R.layout.fragment_top_rated, container,false); ListView list = (ListView)v.findViewById(R.id.listView1); SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.listview_layout, from, to); list.setAdapter(adapter); return v; } }
listview_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:id="@+id/flag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/hello_world" android:paddingTop="10dp" android:paddingRight="10dp" android:paddingBottom="10dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15dp" /> <TextView android:id="@+id/cur" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="10dp" /> </LinearLayout> </LinearLayout>
fragment_top_rated.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > </ListView> </RelativeLayout>