Reputation: 11
When I used ListView and write a adapter extends BaseAdapter comes out this error. And I am sure that I haven't add any thing in the ListView Tag.
This is my main_layout.xml
<LinearLayout
android:id="@+id/layout_map"
android:layout_width="match_parent"
android:layout_height="1200px"
android:layout_below="@+id/toolbar"
android:orientation="horizontal">
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout_map"
android:clickable="true"
android:orientation="vertical">
<ListView
android:id="@+id/lv_stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:clickable="true"></ListView>
</LinearLayout>
This is my list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/stopImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="5"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_height="fill_parent">
<TextView
android:id="@+id/stop_name_item"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_height="fill_parent" />
<TextView
android:id="@+id/stop_info_item"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
</ListView>
And this is my adapter
public class MainActivityStopAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Stop> stopList = null;
public MainActivityStopAdapter(Context mContext, ArrayList<Stop> mList) {
this.mContext = mContext;
this.stopList = mList;
}
public int getCount() {
return stopList.size();
}
public Object getItem(int pos){
return stopList.get(pos);
}
public long getItemId(int pos){
return pos;
}
public View getView(final int pos, View convertView, ViewGroup p){
final ViewHolder viewHolder;
if(convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.stop_list_item,null);
viewHolder = new ViewHolder();
viewHolder.stopImage = (ImageView)convertView.findViewById(R.id.stopImage);
viewHolder.stopName = (TextView)convertView.findViewById(R.id.stop_name_item);
viewHolder.stopInfo = (TextView)convertView.findViewById(R.id.stop_info_item);
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.stopImage.setImageResource(R.drawable.ic_bus_stop);
viewHolder.stopName.setText(stopList.get(pos).getName());
viewHolder.stopInfo.setText(stopList.get(pos).getId());
return convertView;
}
public static class ViewHolder{
public ImageView stopImage;
public TextView stopName;
public TextView stopInfo;
}
}
Upvotes: 1
Views: 712
Reputation: 152927
Remove the ListView
root element in your list_item
layout. The child LinearLayout
is sufficient as the root element in the layout.
ListView
should not have children declared in XML, and putting a ListView
inside a ListView
row item makes no sense anyway.
Upvotes: 2