【发布时间】:2014-01-09 01:36:08
【问题描述】:
开发人员好日子,我已经使用基本适配器实现了 listview,现在我想在 listview 行项目中添加一个视图分页器,目前位于第 2 行。但我遇到了错误。我认为,这是关于列表视图上的 MeasureSpec。
这是使用 BaseAdapter 的 ListView 适配器:
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;
}
}
编辑:
这是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。
【问题讨论】:
-
有人可以帮忙吗?
-
查看此链接。可能会有所帮助stackoverflow.com/questions/14920459/…
-
始终,在发布堆栈跟踪时,突出显示引发异常的行(适配器的
getView()方法中的行402)。
标签: android eclipse android-listview android-viewpager