2
嗨我創建了一個列表視圖和項目,該項目包含2個線性佈局,我想要看到這些佈局,取決於值,我試圖做到這一點getview的適配器,但它不能正常工作我的代碼顯示在下面
Item.xmlAndroid:listview項目問題?
<LinearLayout android:id="@+id/LinearLayout00"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:gravity="fill_horizontal"
android:hapticFeedbackEnabled="true"
android:layout_gravity="fill_horizontal"
android:alwaysDrawnWithCache="true" android:background="#ccc"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:orientation="horizontal"
android:gravity="fill_horizontal"
android:hapticFeedbackEnabled="true"
android:layout_gravity="fill_horizontal"
android:alwaysDrawnWithCache="true" android:background="#ccc"
android:layout_height="wrap_content">
<ImageView android:id="@+id/image"
android:layout_width="50dip" android:layout_height="50dip"
android:src="@drawable/stub" android:scaleType="centerCrop"
android:background="#000000" android:layout_margin="5dip" />
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_width="fill_parent" android:orientation="vertical"
android:paddingLeft="5dip" android:paddingRight="5dip">
<TextView android:id="@+id/text" android:text="Username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:layout_gravity="left|center_vertical"
android:textColor="#111" />
<TextView android:layout_height="wrap_content"
android:id="@+id/Story" android:text="Story"
android:layout_width="fill_parent" android:textColor="#111"
android:textColorHighlight="#06f" android:textStyle="bold"
android:typeface="sans" android:textSize="15dip" />
<TextView android:layout_height="wrap_content"
android:id="@+id/Time" android:text="12 hours ago"
android:layout_width="fill_parent" android:textColor="#333"
android:textSize="11dip" android:paddingBottom="5dip" />
<TextView android:layout_height="wrap_content"
android:id="@+id/Pid" android:visibility="gone"
android:layout_width="fill_parent" android:textSize="0dip" />
</LinearLayout>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_width="fill_parent" android:orientation="vertical"
android:visibility="gone" android:paddingLeft="5dip"
android:paddingRight="5dip">
<TextView android:layout_height="wrap_content"
android:id="@+id/follows" android:text="12 hours ago"
android:layout_width="fill_parent" android:textColor="#333"
android:textSize="11dip" android:paddingBottom="5dip" />
<TextView android:layout_height="wrap_content"
android:id="@+id/followData" android:text="Click"
android:clickable="true" android:layout_width="fill_parent"
android:textColor="#333" android:textSize="11dip"
android:paddingBottom="5dip" />
</LinearLayout>
</LinearLayout>
的java文件
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
ViewHolder holder;
Post o=listItems1.get(position);
if(convertView==null){
vi = inflater.inflate(R.layout.item, null);
holder=new ViewHolder();
LinearLayout ly1=(LinearLayout)vi.findViewById(R.id.LinearLayout01);
LinearLayout ly2=(LinearLayout)vi.findViewById(R.id.LinearLayout02);
if(o.getPostType().equals("0"))
{
ly1.setVisibility(View.VISIBLE);
ly2.setVisibility(View.GONE);
}
else
{
ly2.setVisibility(View.VISIBLE);
ly1.setVisibility(View.GONE);
}
//ly.setVisibility(View.VISIBLE);
holder.text=(TextView)vi.findViewById(R.id.text);
holder.story=(TextView)vi.findViewById(R.id.Story);
holder.timeSpan=(TextView)vi.findViewById(R.id.Time);
holder.image=(ImageView)vi.findViewById(R.id.image);
holder.pid=(TextView)vi.findViewById(R.id.Pid);
holder.follows=(TextView)vi.findViewById(R.id.follows);
holder.followsData=(TextView)vi.findViewById(R.id.followData);
vi.setTag(holder);
}
else
holder=(ViewHolder)vi.getTag();
holder.text.setText(o.getUserName());
holder.story.setText(Html.fromHtml(o.getStory()));
holder.timeSpan.setText(o.getTime());
holder.pid.setText(""+o.getPid());
holder.image.setTag(listItemsUrl.get(position).toString());
imageLoader.DisplayImage(listItemsUrl.get(position).toString(), activity, holder.image);
return vi;
}
請幫我
注意奧古斯丁
謝謝你rekaszeru這解決了我的問題... :-) – augustine 2011-05-03 09:28:41