我在 ViewSwitcher 中有一个列表视图,它在 android 版本 2.2 中运行良好,但它没有显示在我的具有 android 4.1.2 版本的设备中。
我还对其进行了调试,没有看到任何错误,还检查了我传递给适配器的列表是否不为空,并看到它不为空。
我有另一个列表视图,它位于正确显示的 TabHost 中。
问候
编辑:
这是我的代码:
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewswitcher"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
android:layout_gravity="center|top"
>
<TextView
android:id="@+id/dateLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/lblChooseaDate" />
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center" />
<Button
android:id="@+id/btnChooseDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/startdayexpensebtn" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
>
<TextView
android:id="@+id/descLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:text="@string/lbldaydescription" />
<EditText
android:id="@+id/dayDesctiptionText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:singleLine="false"
android:minLines="1"
android:maxLines="3"
android:inputType="textMultiLine" />
<Button
android:id="@+id/addnewItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:enabled="false"
android:text="@string/btnAddnewItem" />
<LinearLayout
android:id="@+id/listcontaioner"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scrollbars="vertical"
>
<ListView
android:id="@+id/android:list"
android:divider="#bababa"
android:dividerHeight="1dp"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/btnlinearlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:paddingRight="10dp"
android:paddingLeft="10dp" >
<Button
android:id="@+id/cancelbtn"
android:layout_weight="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btncancel" />
<Button
android:id="@+id/savebtn"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnAdd" />
</LinearLayout>
</LinearLayout>
</ViewSwitcher>
也为每一行:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp" >
<ImageView
android:id="@+id/expenselisitem_imgaetype"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="35dp"
android:src="@drawable/fail" />
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/expenselisitem_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/expenselisitem_category"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/expenselisitem_desc"
android:paddingBottom="6dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/expenselisitem_amount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBaseline="@+id/expenselisitem_category"
android:layout_alignBottom="@+id/expenselisitem_category"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:paddingBottom="6dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</LinearLayout>
这是适配器:
public class CustomAddExpenseItemListAdapter extends BaseAdapter {
private ArrayList<ExpenseItem> _list=new ArrayList<ExpenseItem>();
private final Activity _context;
private static LayoutInflater inflater=null;
public CustomAddExpenseItemListAdapter(Activity activity,ArrayList<ExpenseItem> data){
_list = data;
_context=activity;
}
public long getItemId(int position) {
return position;
}
public int getCount() {
return _list.size();
}
public Object getItem(int position) {
return position;
}
static class ViewHolder {
protected TextView _cexpenseDesctiption;
protected TextView _cAmount;
protected ImageView _cType;
protected TextView _cCategory;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=null;
if(convertView==null)
{
inflater = _context.getLayoutInflater();
vi = inflater.inflate(R.layout.expense_item_list_row, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder._cexpenseDesctiption= (TextView) vi.findViewById(R.id.expenselisitem_desc);
viewHolder._cAmount = (TextView) vi.findViewById(R.id.expenselisitem_amount);
viewHolder._cType=(ImageView)vi.findViewById(R.id.expenselisitem_imgaetype);
viewHolder._cCategory=(TextView)vi.findViewById(R.id.expenselisitem_category);
vi.setTag(viewHolder);
}
else
{
vi = convertView;
}
ViewHolder holder = (ViewHolder) vi.getTag();
ExpenseItem item;
item = _list.get(position);
holder._cexpenseDesctiption.setText(item.get_description());
holder._cAmount.setText(String.valueOf(item.get_amount()));
if(item.get_type()==0)
{
holder._cCategory.setText(item.get_category().get_title());
holder._cType.setImageResource(R.drawable.downarrow);
}
else
{
holder._cCategory.setText("-");
holder._cType.setImageResource(R.drawable.uparrow);
}
return vi;
}
}