Хороший день Разработчики, я уже реализую listview с помощью базового адаптера, и теперь я хочу добавить пейджер представления в элемент списка listview, в настоящее время в строке 2, но я столкнулся с ошибкой. Я думаю, речь идет о MeasureSpec в списке.Как добавить ViewPager, содержащий изображения в список?
Это ListView адаптер с помощью BaseAdapter:
public class ListViewAdapter extends BaseAdapter {
...
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
View v = convertView;
TextView txt_urutan;
TextView txt_menu;
TextView txt_price;
ImageView img_menu;
ImageView img_arrow;
if(v==null){
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.list_makanan, parent, false);
}
img_menu = (ImageView)v.findViewById(R.id.picture_menu_on_listview);
txt_urutan = (TextView)v.findViewById(R.id.urutan_makanan_ayam_listview);
txt_menu = (TextView)v.findViewById(R.id.nama_makanan_ayam_listview);
txt_price = (TextView)v.findViewById(R.id.harga_makanan_ayam_listview);
img_arrow = (ImageView)v.findViewById(R.id.arrow_on_listview);
txt_urutan.setText(urutan_makanan_sambal[pos]);
txt_menu.setText(jenis_menu_sambal[pos]);
txt_price.setText(price_menu_sambal[pos]);
img_menu.setImageResource(pic_menu.getResourceId(pos, -1));
img_arrow.setImageResource(R.drawable.nav_icon);
return v;
}
}
EDIT:
Это horizontalscrollview.java:
public class HorizontalScrollViewAdapter extends BaseAdapter{
LayoutInflater inflater;
Context context;
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ImageView img;
if(v==null){
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.horizontal_scroll_view, parent, false);
}
img = (ImageView)v.findViewById(R.id.image_view1);
return v;
}
}
это siteContentView класс:
public class SiteContentPreview{
public View getView(Context context, View v, SiteContentData siteContent){
View result = v;
if(result!=null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
result = inflater.inflate(R.layout.custom_image, null);
}
TextView siteNumber = (TextView)result.findViewById(R.id.custom_image_view_text);
ImageView siteImage = (ImageView)result.findViewById(R.id.custom_image_view);
if(siteContent != null){
siteNumber.setText(siteContent.getSiteNumber());
siteImage.setImageResource(Integer.parseInt(siteContent.getSiteContentFrame()));
}
return result;
}
}
это siteContentData класс:
public class SiteContentData{
String holdString;
String holdImagePath;
public getSiteNumber(){
return holdString;
}
public getSiteContentFrame(){
return holdImagePath;
}
}
Это horizontal_scroll_view.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="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp" >
<LinearLayout
android:id="@+id/hori_place_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
и это scroll_view.xml (для хранения изображений, которые должны быть размещены внутри горизонтальной прокрутки зрения):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView android:id="@+id/image_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sambal_bajak_laut"/>
<ImageView android:id="@+id/image_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sambal_bawang"/>
</LinearLayout>
любая помощь или идея были бы очень оценены. Окружающая среда: Eclipse, ADT, Genymotion.
есть ли кто может помочь? – Hendy
Посмотрите эту ссылку. Возможно, будет какая-то помощь http://stackoverflow.com/questions/14920459/placing-viewpager-as-a-row-in-listview –
** Всегда ** при отправке stacktrace выделите строку, где исключение (строка '402' в методе' getView() 'вашего адаптера). – Luksprog