但它只在kitkat设备上崩溃,而且它也适用于kitkat模拟器,所以我在logcat中没有任何东西。
如果我删除imageView.setImageResource(imageId.get(position))
应用程序也适用于kitkat设备,但我需要它。
这是我的代码:
CustomList:
public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final List<String> names;
private final List<Integer> imageId;
private Typeface myFont;
public CustomList(Activity context, List<String> names, List<Integer> imageId) {
super(context, R.layout.list_single, names);
this.context = context;
this.names = names;
this.imageId = imageId;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
SharedPreferences sp = context.getSharedPreferences("settings", 0);
String font_name = sp.getString("font", "yeken.ttf");
float text_size = sp.getFloat("size", 18);
if (font_name.equals("yeken.ttf")) {
myFont = Typeface.createFromAsset(context.getAssets(), font_name);
}
else
myFont = android.graphics.Typeface.DEFAULT;
txtTitle.setText(names.get(position));
if (myFont != null)
txtTitle.setTypeface(myFont);
txtTitle.setTextSize(text_size);
imageView.setImageResource(imageId.get(position));
return rowView;
}
}
list_single.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow android:gravity="right" android:background="@drawable/list_item_bg2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="test" android:gravity="center"/>
<ImageView
android:id="@+id/img"
android:layout_width="70dip"
android:layout_height="70dip"
android:src="@drawable/gray_button" android:layout_marginLeft="10dip" android:layout_marginRight="10dip"/>
</LinearLayout>
</TableRow>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_margin="2dip"
android:background="@drawable/list_devider" />
</TableLayout>