改变对象的顺序列表视图中排programmaticaly [英] change order of object in row of listview programmaticaly
本文介绍了改变对象的顺序列表视图中排programmaticaly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我有:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15:22:33 \nApr 13 1999"
android:textColor="#FFFFFFFF"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dip"
android:background="@drawable/incoming_message_buble"
android:paddingLeft="10dip"
android:text="Hello bubbles!"
android:textColor="@android:color/primary_text_light" />
和它做工精细。
下面是适配器code:
here is adapter code:
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.activity_sms_row_layout, parent, false);
}
wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
OneComment coment = getItem(position);
countryName = (TextView) row.findViewById(R.id.comment);
countryName.setText(coment.comment);
countryName.setBackgroundResource(coment.left ? R.drawable.incoming_message_buble : R.drawable.outgoing_message_buble);
wrapper.setGravity(coment.left ? Gravity.LEFT : Gravity.RIGHT);
return row;
}
我要改变顺序,重力离开,我需要先所示TextView的评论,和textView1第二
重力权利,保留XML设置。
i have to change order, for gravity left, i need shown textview comment first, and textView1 second for gravity right, keep xml setting.
请告知。
推荐答案
我建议使用多个布局,而不是不断地重组每个行的布局。覆盖这两种方法:
I suggest using multiple layouts rather than constantly reorganizing each row's layout. Override these two methods:
@Override
public int getItemViewType(int position) {
return getItem(position).left ? 0 : 1;
}
@Override
public int getViewTypeCount() {
return 2;
}
和修改 getView()
:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(getItemViewType == 0) {
// Use the left layout
} else {
// Use the right layout
}
}
这篇关于改变对象的顺序列表视图中排programmaticaly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文