我有一个只有行布局中的图片的GridView 但我继续用" title"来获取这个不需要的TextView。其中的文字
我搜索了行xml文件和所有代码,但我找不到这个TextView来自哪里
fragment_category_layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp">
<TextView style="@style/WizardPageTitle" />
<GridView
android:id="@+id/gridCategoryList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:columnWidth="125dp"
android:drawSelectorOnTop="true"
android:listSelector="@drawable/grid_selector"
android:gravity="center"
android:numColumns="3"
android:padding="2dp"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:focusable="true"
android:clickable="false"/>
</RelativeLayout>
category_row
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ededed">
<ImageView
android:id="@+id/categoryImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_cat_cars" />
</LinearLayout>
fragment_category
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_category_layout, container, false);
txtTitle = ((TextView) rootView.findViewById(android.R.id.title));
txtTitle.setText(mPage.getTitle());
final int[] icons = new int[mChoices.size()];//mChoices.toArray(]);
for (int i = 0; i < icons.length; i++)
icons[i] = Integer.valueOf(mChoices.get(i));
GridView gridView = (GridView) rootView.findViewById(R.id.gridCategoryList);
gridView.setAdapter(new CategoryAdapter(getActivity(), icons));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
if (previousSelectedView != null) previousSelectedView.setSelected(false);
v.setSelected(true);
previousSelectedView = v;
mPage.getData().putString(Page.SIMPLE_DATA_KEY,
String.valueOf(icons[position]));
wizSession.setValue(pageKey, String.valueOf(position + 1));
//wizSession.setValue(Page.SIMPLE_DATA_KEY, String.valueOf(position + 1));
//mPage.getData().putString(Page.SIMPLE_DATA_KEY, String.valueOf(position + 1));
mPage.notifyDataChanged();
}
});
return rootView;
}
Category_adapter
public class CategoryAdapter extends BaseAdapter {
int[] mCategoryImg;
LayoutInflater inflater;
public CategoryAdapter(Context context, int[] imageItems) {
this.mCategoryImg = imageItems;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mCategoryImg.length;
}
@Override
public Object getItem(int i) {
return mCategoryImg[i];
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View rootView = inflater.inflate(R.layout.category_row, null);
ImageView imageView = (ImageView) rootView.findViewById(R.id.categoryImage);
imageView.setImageResource(mCategoryImg[i]);
return rootView;
}
}
图片来说明我的意思 highlighted with red
答案 0 :(得分:0)
问题解决了,导致问题的原因是我已经包含了一个具有相同布局名称的库(category_item.xml),我只是难以重命名布局并且它已经解决了:D