我有一个布局如下的选项卡应用程序:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom = "@android:id/tabcontent"
/>
</RelativeLayout>
</TabHost>
我想把ListView
它叫做一个屏幕,所以我这样设计:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
和gridview看起来像
<?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="vertical" android:background="#ffffff">
<ImageView
android:id="@+id/imageViewContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textViewCategoryName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dip"
/>
</LinearLayout>
我使用以下方法调用适配器:
SectionsAdapter adapter = new SectionsAdapter(Sections.this ,R.layout.sectionviewgridview,
appState.MainCategories);
// updating listview
setListAdapter(adapter);
适配器看起来像:
public class SectionsAdapter extends ArrayAdapter<HashMap<String, String>>{
ArrayList<HashMap<String, String>> mainCategories;
private final Context context;
public SectionsAdapter(Context context, int ResourceId,
ArrayList<HashMap<String, String>> items)
{
super(context, ResourceId);
this.context = context;
this.mainCategories = items ;
Log.d("The count of the hash is",""+items.size());
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Log.d("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx","I'm hereeeeeeeeeeeeeeeeeeeeeeeeee" );
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.sectionviewgridview, parent, false);
ImageView ImageViewObject = (ImageView)rowView.findViewById(R.id.imageViewContent);
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new java.net.URL(mainCategories.get(position).get("imageUrl")).getContent());
ImageViewObject.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",mainCategories.get(position).get("name"));
TextView TextViewObject = (TextView) rowView.findViewById(R.id.textViewCategoryName);
TextViewObject.setText(mainCategories.get(position).get("name"));
return rowView;
}
}
它从不记录getView
方法中的内容。知道如何解决吗?