我有一个习俗,里面DialogFragment
有一个习俗View
。那View
有一个ListView
int它。我想在按下按钮或触发事件后立即显示它。仅在第View
一次调用它时才显示几秒钟,1 到 2 秒。接下来它必须出现,它立即出现,或者如果有延迟,它只需要大约 100-200ms。
我正在创建View
每次调用它的新实例,所以我认为它也应该需要几秒钟才能显示。
有什么解决办法吗?谢谢!
示例代码:
CustomDialogFragment dialog = new CustomDialogFragment();
dialog.show(getSupportFragmentManager(), "a_tag");
这是对话框:
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class CustomDialogFragment extends DialogFragment implements OnItemClickListener {
private ListView mListView;
private CustomAdapter mAdapter;
private ArrayList<Object> mData;
public CustomDialogFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.custom_dialog_fragment, container);
return view;
}
@Override
public void onActivityCreated(Bundle arg0) {
super.onActivityCreated(arg0);
mListView = (ListView) getView().findViewById(R.id.lst);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mData = new ArrayList<Object>();
mAdapter = new CustomAdapter(getActivity(), mData);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO : Do something here
}
}
这是Adapter
:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<Object> data;
private static LayoutInflater inflater;
public CustomAdapter(Activity a, ArrayList<Object> d) {
this.activity = a;
this.data = d;
inflater = ((LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
}
@Override
public int getCount() {
return this.data.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
v = inflater.inflate(R.layout.table_row, null);
}
// TODO : Edit some UI here
return v;
}
}