我正在将我的类扩展到ListFragment。下面是我贴的亲戚。
我的问题是,我没有在运行时得到任何错误,但在输出它仍然加载页面。
输出:
管理.java:
public class Administration extends ListFragment {
int[] img = { R.drawable.project, R.drawable.user, R.drawable.group,
R.drawable.roles, R.drawable.news, R.drawable.document };
private String item[] = { "Project", "Users", "Group",
"Roles and Permission", "News", "Documents" };
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getListView().setDividerHeight(2);
getListView().setAdapter(new BindDataAdapter(getActivity(), img, item));
}
@SuppressWarnings("deprecation")
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
for (int a = 0; a < l.getChildCount(); a++) {
l.getChildAt(a).setBackgroundColor(Color.TRANSPARENT);
}
}
}
我没有在ListFragment中使用任何布局。
binddataadapter.java:
public class BindDataAdapter extends BaseAdapter {
Activity mLocal;
int[] imgArray;
String titleA[];
LayoutInflater mLayoutInflater;
public BindDataAdapter(Activity administration, int[] imageArray, String[] title) {
mLocal = administration;
imgArray = imageArray;
titleA = title;
mLayoutInflater = (LayoutInflater) administration
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return imgArray.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
private class Holder {
ImageView image;
TextView textView;
}
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder = null;
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.activity_list, null);
holder = new Holder();
holder.image = (ImageView) convertView.findViewById(R.id.iamge);
holder.textView = (TextView) convertView.findViewById(R.id.text1);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.image.setBackgroundResource(imgArray[position]);
holder.textView.setText(titleA[position]);
return convertView;
}
}
活动列表.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/whitelist"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/iamge"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="4dp"
android:contentDescription="@string/app_name" >
</ImageView>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:padding="@dimen/padding_medium"
android:paddingLeft="10dp"
android:text="@string/hello_world"
android:textColor="@android:color/black"
android:textStyle="bold"
/>
</LinearLayout>
我不知道为什么它一直在加载。非常感谢您的帮助。谢谢。
最佳答案
显示进度条可能是ListFragment的默认内置进度。因此,在将ListView的适配器设置为:
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
.....
setListShown(true);
}
关于android - Android:ListFragment持续加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27833192/