Android单选对话框需要一些时间来响应

时间:2014-02-01 09:01:45

标签: android android-layout

在我的应用程序内部我正在显示一个标准的简单选择对话框。它有120个上衣。在创建并显示之后,当我尝试滚动它时,开始响应和滚动大约需要3-4秒。在那之后它的运行和反应顺利。什么可以做立即开始滚动?

编辑:这是我的代码:

在活动中,这是我创建对话框的方式:

ArrayList<MyListItem> items = new ArrayList<MyListItem>();
// then my list is created by filtering a bigger list, the new one has about 50-100 items

MyListItem[] choiceItems; = new MyListItem[items.size()];
for (int j=0; j<items.size(); j++) {
    choiceItems[j] = items.get(j);
}

MyListAdapter adapter = new MyListAdapter(this, R.layout.my_list_row, choiceItems);

DialogInterface.OnClickListener myListSingleListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
        processClickedItem( which );
    }
};

AlertDialog.Builder adBuilder = new AlertDialog.Builder(this);
adBuilder.setSingleChoiceItems(adapter, -1, myListSingleListener);
AlertDialog dialog = adBuilder.create();
dialog.show();

MyAdapter.java:

public class MyListAdapter extends ArrayAdapter<MyListItem> {

    Context context; 
    int layoutResourceId;    
    MyListItem items[] = null;

    public MyListAdapter(Context context, int textViewResourceId, MyListItem[] objects) {
        super(context, textViewResourceId, objects);
        this.layoutResourceId = textViewResourceId;
        this.context = context;
        this.items = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        MyItemHolder holder = null;
        if (row == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new MyItemHolder();
            holder.txtTitle = (TextView) row.findViewById(R.id.tvMyListTitle);
            holder.icon = (ImageView) row.findViewById(R.id.iconMyList);
            holder.txtTitle.setText(title);
            holder.icon.setImageResource(R.drawable.icon_no_error);
            row.setTag(holder);
        } else {
            holder = (MyItemHolder)row.getTag();
        }
        return row;
    } 

    static class MyItemHolder  {
        TextView txtTitle;
        ImageView icon;
    }    

}

和布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:weightSum="12" >

    <TextView
        android:id="@+id/tvMyListTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:text="TextView"
        android:textColor="@color/black"
        android:textSize="14sp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/iconMyList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="11"
        android:maxHeight="45dp"
        android:src="@drawable/icon_blank" />

</LinearLayout>

对话框立即显示,没有延迟。我第一次尝试滚动它。

0 个答案:

没有答案