MainActivity.java
public class MainActivity extends AppCompatActivity {
private String[] names = new String[]{"name1", "name2", "name3"};
private String[] says = new String[]{"desc1", "desc2", "desc3"};
private int[] imgIds = new int[]{R.mipmap.head_icon1, R.mipmap.head_icon2, R.mipmap.head_icon3};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<Map<String, Object>> listitem = new ArrayList<Map<String, Object>>();
for (int i = 0; i < names.length; i++) {
Map<String, Object> showitem = new HashMap<String, Object>();
showitem.put("touxiang", imgIds[i]);
showitem.put("name", names[i]);
showitem.put("says", says[i]);
listitem.add(showitem);
}
//create one simpleAdapter
SimpleAdapter myAdapter = new SimpleAdapter(getApplicationContext(), listitem, R.layout.list_item, new String[]{"touxiang", "name", "says"}, new int[]{R.id.imgtou, R.id.name, R.id.says});
ListView listView = (ListView) findViewById(R.id.list_test);
listView.setAdapter(myAdapter);
}
}
list_item.xml
<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/imgtou"
android:layout_width="64dp"
android:layout_height="64dp"
android:baselineAlignBottom="true"
android:paddingLeft="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:textColor="#1D1D1C"
android:textSize="20sp" />
<TextView
android:id="#+id/says"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8px"
android:textColor="#B4B4B9"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
but these images can be recognized by android studio.
anyone can help to find the problem?
You've used SimpleAdapter in your code.
But usage was wrong.
SimpleAdapter haven't image id as parameter.
Please look following URL.
https://developer.android.com/reference/android/widget/SimpleAdapter
public SimpleAdapter (Context context,
List<? extends Map<String, ?>> data,
int resource,
String[] from,
int[] to)
context(Context): The context where the View associated
with this SimpleAdapter is running data List: A List of Maps. Each
entry in the List corresponds to one row in the list. The Maps
contain the data for each row, and should include all the entries
specified in "from"
resource(int): Resource identifier of a view
layout that defines the views for this list item. The layout file
should include at least those named views defined in "to"
from(String): A list of column names that will be added to the Map
associated with each item.
to(int): The views that should display
column in the "from" parameter. These should all be TextViews. The
first N views in this list are given the values of the first N
columns in the from parameter.
But you used image ids array to "to" fields.
//create one simpleAdapter
SimpleAdapter myAdapter = new SimpleAdapter(
getApplicationContext(),
listitem,
R.layout.list_item,
new String[]{"touxiang", "name", "says"},
new int[]{R.id.imgtou, R.id.name, R.id.says} //You used wrong values. This should be textview ids.
);
So you cannot use SimpleAdapter with your purpose.
You should customize Adapter class to your purpose.
SimpleAdapter myAdapter = new SimpleAdapter(
getApplicationContext(),
listitem,
R.layout.list_item,
new String[]{"touxiang", "name", "says"},
new int[]{R.mipmap.head_icon1, R.mipmap.head_icon2, R.mipmap.head_icon3}
);
Or you can use Picasso Library for setting and Loading Images.
Related
I am retrieving data from sqlite and showing it in a listview using simpleadapter.I don't have any issues regarding Layouts.Still just for your reference :
list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<!-- Name Label -->
<TextView
android:id="#+id/subject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#421fc4"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/day"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:textStyle="bold" />
<TextView
android:id="#+id/slot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textColorHighlight="#782086"
android:textStyle="bold" />
<TextView
android:id="#+id/instructor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#782086"
android:textStyle="bold" />
</LinearLayout>
I am having problem somewhere in the following code snippet.I tried to retrieve the data from sqlite using normal listview and it worked perfect.But when i used this code snippet for custom listview using SimpleAdapter i get only the last row of the result of the query.That last row's data gets repeated 8 times in the listview as there are 8 rows in the result of the query.
HashMap<String, String> hashMap = new HashMap<String, String>();
ArrayList<HashMap<String, String>> Timetablelist;
//c being the cursor
if (c.moveToFirst()) {
do {
String subject = c.getString(c.getColumnIndex(dba.KEY_SUBJECT));
String day = c.getString(c.getColumnIndex(dba.KEY_DAY));
String slot = c.getString(c.getColumnIndex(dba.KEY_SLOT));
String instructor = c.getString(c.getColumnIndex(dba.KEY_INSTRUCTOR_NAME));
// adding each child node to HashMap key => value
hashMap.put("Subject", subject);
hashMap.put("Day", day);
hashMap.put("Slot", slot);
hashMap.put("Instructor", instructor);
Timetablelist.add(hashMap);
ListAdapter adapter = new SimpleAdapter(
this, Timetablelist,R.layout.list_item, new String[] { "Subject", "Day",
"Slot","Instructor" }, new int[] { R.id.subject,
R.id.day, R.id.slot,R.id.instructor });
setListAdapter(adapter);
}while (c.moveToNext());
}
P.S : I was able to retrieve data using normal listview.So database and other layouts are working fine.
Move the below out of do While
ListAdapter adapter = new SimpleAdapter(
this, Timetablelist,R.layout.list_item, new String[] { "Subject", "Day",
"Slot","Instructor" }, new int[] { R.id.subject,
R.id.day, R.id.slot,R.id.instructor });
setListAdapter(adapter);
You get the data from database and you can populate Timetablelist in the do while. But there is no need to initialize adapter everytime and setListAdapter.
Edit:
HashMap<String, String> hashMap ;
ArrayList<HashMap<String, String>> Timetablelist = new ArrayList<HashMap<String,String>>();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
String subject = c.getString(c.getColumnIndex(dba.KEY_SUBJECT));
String day = c.getString(c.getColumnIndex(dba.KEY_DAY));
String slot = c.getString(c.getColumnIndex(dba.KEY_SLOT));
String instructor = c.getString(c.getColumnIndex(dba.KEY_INSTRUCTOR_NAME));
// adding each child node to HashMap key => value
hashMap = new HashMap<String, String>();
hashMap.put("Subject", subject);
hashMap.put("Day", day);
hashMap.put("Slot", slot);
hashMap.put("Instructor", instructor);
Timetablelist.add(hashMap);
}
ListAdapter adapter = new SimpleAdapter(
this, Timetablelist,R.layout.list_item, new String[] { "Subject", "Day",
"Slot","Instructor" }, new int[] { R.id.subject,
R.id.day, R.id.slot,R.id.instructor });
setListAdapter(adapter);
I have been working on trying to implement two listviews inside a list fragment, I have stated two list views in my xml and tried to set two seperate sets of data in the java file but the list view data intended for the first lisview is overwritten by the second.
How would I be able to point it to the correct listviews using the code below?
Java for fragment where list should go:
package com.owais.shopsellswap;
import java.util.ArrayList;
import java.util.HashMap;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
public class Fragment_My_Profile extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myProfileView = inflater.inflate(R.layout.fragment_my_profile, container, false);
return myProfileView;
}
// Store Arralist as hashmaps for the listview
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
ArrayList<HashMap<String,String>> list2 = new ArrayList<HashMap<String,String>>();
// SimpleAdapter (listViewAdapter) links the array to the listview
private SimpleAdapter listViewAdapter;
private SimpleAdapter listViewAdapter2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//HashMap links each line of data to the correct TextView
HashMap<String,String> item;
for(int i=0;i<userInfo.length;i++){
item = new HashMap<String,String>();
item.put( "line1", userInfo[i][0]);
item.put( "line2", userInfo[i][1]);
list.add( item );
}
HashMap<String,String> item2;
for(int i=0;i<ListingsArray.length;i++){
item2 = new HashMap<String,String>();
item2.put( "line1", ListingsArray[i][0]);
item2.put( "line2", ListingsArray[i][1]);
item2.put( "line3", ListingsArray[i][2]);
list2.add( item2 );
}
listViewAdapter = new SimpleAdapter(getActivity(), list,
R.layout.listview_layout_1,
new String[] { "line1","line2" },
new int[] {R.id.line_a, R.id.line_b});
listViewAdapter2 = new SimpleAdapter(getActivity(), list2,
R.layout.listview_layout_3,
new String[] { "line1","line2", "line3" },
new int[] {R.id.line_a1, R.id.line_b1, R.id.line_c1});
setListAdapter(listViewAdapter);
setListAdapter(listViewAdapter2);
}
private String[][] userInfo =
{{"User","Dummy"},
{"Email Address","Dummy#dummymail.com"},
{"User Type","Staff"},
{"Contact Number","07111111111"}};
private String[][] ListingsArray =
{{"audi a3","brand new audi a3 with alloywheels, cd player", "£11000"},
{"HTC One x","brand new android smartphone", "£450"},
{"Acer Laptop","Acer Laptop with windows 7", "£300"},
{"Sunglass","Oakley Sunglasses in great condition", "£100"}};
}
xml for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/lightgrey"
android:text="#string/userInfoHeader"
android:textSize="15sp"
android:textStyle="bold" />
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="184dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2" >
</ListView>
<TextView
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/android:list"
android:background="#color/lightgrey"
android:text="#string/listingsHeader"
android:textSize="15sp"
android:textStyle="bold" />
<ListView
android:id="#+id/android:list2"
android:layout_width="fill_parent"
android:layout_height="184dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
</ListView>
</RelativeLayout>
The list view also uses a custom layout for each list.
You need to set the two adapters accordingly with each ListView....
ListView list = (ListView)findViewById(R.id.list);
ListView list2 = (ListView)findViewById(R.id.list2);
list.setAdapter(...)
list2.setAdapter(...)
...however you do not have two ListViews in play. In using a ListFragment each time you call setAdapter you are setting a single ListView to the given contents. You would need to adjust your ListFragement to be that of a Fragment and have two separate ListViews within the Fragment, then set each with its own adapter as mentioned above.
setListAdapter assumes the default target. To set the second adapter you need to find the second listview id and then set the second adapter to it.
listview = findViewById(R.id.list2);
listview.setAdapter(adapter2);
Note that a listfragment usually expects only a single list so the above.might not work, you may need to just use a regular fragment and do the above.for both lists.
I have a Listview. In that Listview I have multiple textviews and again a listview.
First I always used the simpleadapter to fill my Listviews with data. But now I have added embedded a listview.
Which Adaplter do I have to use?! Because I think that this is not possible with the simpleadapter.
Main Activity layout:
<ListView
android:id="#+id/lvData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#drawable/border_ui"
android:divider="#color/dark_grey"
android:dividerHeight="1dp"
android:padding="4dp" />
Listview (lvData) item layout
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tv_deposit_depiting" />
<ListView
android:id="lvDepositDepitingList"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
I always used the simple adapter that way:
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
for (Deposit deposit : getCurrentList()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", deposit.getName());
map.put("amount", String.valueOf(deposit.getAmount()));
list.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, list,
R.layout.list_item_layout_deposit, new String[] { "name",
"amount" }, new int[] { R.id.tvDepositName,
R.id.tvDepositCurrentMonth });
lvData.setAdapter(adapter);
I think I will have to extend an adapter and write a custom one. If that is what I have to do, which adapter should I extend?
Thanks!
Yes you can create a class extending BaseAdapter and customize the view as you would like, check this link for help and guidelines Custom Adapter Guide
I have a mutlicolumn list in which I also want one of the columns to include a drop down spinner.
My main.xml is: -
<!-- main.xml -->
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/SCHEDULE" android:layout_width="wrap_content" android:layout_height="wrap_content">
</ListView>
My row xml is
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/LEVEL_CELL"
android:layout_width="50dip"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/ACTION_CELL"
android:layout_width="50dip"
android:layout_height="wrap_content"/>
<Spinner
android:id="#+id/fromTables"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Here is my logic: -
super.onCreate(savedInstanceState);
setContentView(R.layout.row);
fromTablesSpinner = (Spinner) findViewById(R.id.fromTables);
setContentView(R.layout.main);
ListView list = (ListView) findViewById(R.id.SCHEDULE);
ArrayList<String> tables = new ArrayList<String>();
tables.add("MARA");
tables.add("MARC");
tables.add("MARD");
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("level", "1");
map.put("action", "INNER JOIN");
map.put("tables", "MARA");
map.put("tables", "MARC");
mylist.add(map);
map = new HashMap<String, String>();
map.put("level", "2");
map.put("action", "OUTER JOIN");
map.put("tables", "MARA");
map.put("tables", "MARC");
mylist.add(map);
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.row,
new String[] { "level", "action" }, new int[] {
R.id.LEVEL_CELL, R.id.ACTION_CELL });
list.setAdapter(mSchedule);
}
The use of SimpleAdapter does not allow me to bind to a spinner view.
Any help is much appreciated.
Thanks
Martin
You are trying two complicated things at once. Follow these steps:
1) Learn to build a custom adapter which shows more than one type of views in a single list. This will help you to show a spinner in the list.
Links : http://www.ezzylearning.com/tutorial.aspx?tid=1763429
Android ListView with different layouts for each row
2) Learn to handle different view and listeners.
Links: Listview with TextView and Button. RowId of the clicked button (btnButtonOFF.setOnClickListener(new ItemClickListener(cur.getInt(idRow)));)
3) Use Multiple ListViews like you are using.
I have a 2-column row layout that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textSize="13sp">
<TextView android:id="#+id/TRAIN_CELL"
android:layout_width="275dip"
android:layout_height="wrap_content"/>
<ImageView android:id="#+id/TO_CELL"
android:layout_width="25dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/arrow_button"/>
</LinearLayout>
And once I fetch items from the database, I display them in the left column, and in the right column I want to have a little image with an arrow signifying that it is a clickable item. But I am not sure how to make the image render. Here is how I currently populate that list:
I have these two variables:
private List<HashMap<String, String>> fillMaps;
private SimpleAdapter adapter;
At first I set them up like this:
list = (ListView) findViewById(android.R.id.list);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
//HashMap<String, String> map = new HashMap<String, String>();
// My data
fillMaps = new ArrayList<HashMap<String, String>>();
adapter = new SimpleAdapter(this, fillMaps, R.layout.questions_list,
new String[] {"train", "to"},
new int[] {R.id.TRAIN_CELL, R.id.TO_CELL});
// This was the middle item R.id.FROM_CELL,
list.setAdapter(adapter);
list.setTextFilterEnabled(true);
and when the data comes back from the server, I populate the list like this:
if ( obj != null )
{
questions.clear();
for ( int i = 0; i < obj.length(); i++ )
{
HashMap<String, String> map = new HashMap<String, String>();
JSONObject o = obj.getJSONObject(i);
question_id = o.getString("question_id");
question = o.getString("question");
question_by_member_id = o.getString("member_id");
Question q = new Question ( );
q.setQuestion( question );
q.setQuestionId( question_id );
q.setQuestionByMemberId(question_by_member_id);
map.put("train", question);
//map.put("from", ">");
//map.put("to", ">");
fillMaps.add(map);
questions.add( q );
}
adapter.notifyDataSetChanged();
}
But I am not getting the image to render. I think part of the problem is that I am using Strings as the data that the list expects, but I am not sure how to handle this with the images. The image is always the same image by the way.
Thanks!! :)
Is this what you want?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textSize="13sp">
<TextView android:id="#+id/TRAIN_CELL"
android:layout_width="275dip"
android:layout_height="wrap_content"/>
<ImageView android:id="#+id/TO_CELL"
android:layout_width="25dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/arrow_button"/>
</LinearLayout>
Addition
(Sorry, sometimes I miss notifications when they pile up over night. I believe you should be able to read messages / remove notifications here on Stack Overflow one by one or all at once, like an inbox...)
Anyway, if TO_CELL's image is always going to be the same, simply set the image in the XML only. Change your SimpleAdapter to this:
adapter = new SimpleAdapter(this, fillMaps, R.layout.questions_list,
new String[] {"train"},
new int[] {R.id.TRAIN_CELL});
Now your adapter only handles one string, you can simplify it to an ArrayAdapter (if you want.)
Simplified Example
You can also display one TextView and display a small "next" arrow like so:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="#android:drawable/ic_media_play"
android:padding="10sp"
android:textAppearance="?android:attr/textAppearanceMedium" />
(A LinearLayout and separate ImageView is not strictly necessary. I saved this as list_item.xml.)
Here is a simple preview, understand that I left a lot of the non-critical lines out to not be repetitive:
public class Example extends Activity {
ArrayAdapter<String> adapter;
List<String> list = new ArrayList<String>();
ListView listView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.text, list);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
updateList();
}
public void updateList() {
...
if ( obj != null ) {
questions.clear();
list.clear();
for ( int i = 0; i < obj.length(); i++ ) {
JSONObject o = obj.getJSONObject(i);
...
question = o.getString("question");
list.add(question);
}
adapter.notifyDataSetChanged();
}
}
}
Hope this helps!
I believe the easiest way is instead of using a SimpleAdapter try extending the ArrayAdapter for your needs. You can override the getView() method and populate your list the way you need!
There are a few examples here, here and here.
EDIT
First, you need a few modifications in your xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textSize="13sp">
<TextView android:id="#+id/TRAIN_CELL"
android:layout_width="275dip"
android:layout_height="wrap_content"/>
<ImageView android:id="#+id/TO_CELL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#fff"/>
</LinearLayout>
In the following code I used a ArrayList of Strings for simplicity. You will have to replace that with a list of whatever object you are using to populate your list. (Question maybe?)
Create an ExtendedAdapter and override the getView() method to do what you intend. This will create a TextView and a ImageView on each row of the list, populate the TextView with the items in your ArrayList items and show the image if the item is clickable. (You have to do the verification by yourself but shouldn't be hard to figure it out)
public class ExtendedAdapter extends BaseAdapter {
public static final String TAG = "TodoAdapter";
private Context mContext;
private int layoutResource;
private boolean clickable = false;
private List<String> items; // you can replace this list with whathever you need
// for simplicity i'm assuming you already have the strings
// you need for the textviews
public ExtendedAdapter(Context context, int textViewResourceId,
List<String> items) {
this.items = items;
this.mContext = context;
this.layoutResource = textViewResourceId;
}
public int getCount() {
return items.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(layoutResource, null);
}
ImageView arrow = (ImageView) v.findViewById(R.id.TO_CELL);
TextView text = (TextView) v.findViewById(R.id.TRAIN_CELL);
text.setText(items.get(position));
if (clickable) // here you have to do your check if it's clickable or not
arrow.setBackgroundResource(R.drawable.ic_launcher);
return v;
}
}
And in your activity, just set the list adapter
public class MainActivity extends Activity {
ListView yourList;
ArrayList<String> itemList = new ArrayList<String>();
ExtendedAdapter adapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
yourList = (ListView) findViewById(R.id.yourList);
adapter = new ExtendedAdapter(this, R.layout.row_layout, itemList);
yourList.setAdapter(adapter);
updateItems();
}
public void updateItems(){
//dummy method, you should fetch your data and populate your array in a separate thread
//or something
itemList.add("Text 1");
itemList.add("Text 2");
itemList.add("Text 3");
itemList.add("Text 4");
itemList.add("Text 5");
itemList.add("Text 6");
adapter.notifyDataSetChanged();
}
}
That's how you create a list with text and image.
Good luck!
I think you should customize the list adapter and it will be easy this way.
The problem is with Layout and with the Simple adpater.
1.do not use linearLayout android:textSize="13sp" use it for TextView,
you can use below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingTop="4dip" >
<TextView
android:id="#+id/TRAIN_CELL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="try out by yourself..."
android:textSize="13sp" />
<ImageView
android:id="#+id/TO_CELL"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".05"
android:gravity="center"
android:src="#android:drawable/arrow_down_float" />
</LinearLayout>
2.The problem is in SimpleAdapter use
adapter = new SimpleAdapter(this, fillMaps, R.layout.questions_list,
new String[] {"train"},
new int[] {R.id.TRAIN_CELL});