Dear friends, scholarship ANDROID, For custom ArrayAdapter. Here is the code:
Custom LAYOUT list_view1_item.xml
android: id = "@ + id / messageArrayAdapterLinerlayout"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: layout_gravity = "center_vertical"
android: orientation = "vertical">android: id = "@ + id / frameLayout_complexMessage"
android: layout_width = "fill_parent"
android: layout_gravity = "center_horizontal"
android: layout_height = "wrap_content">android: id = "@ + id / image_complexMessageTitle"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: scaleType = "centerInside" />android: id = "@ + id / txt_name"
android: layout_width = "fill_parent"
android: layout_gravity = "bottom"
android: gravity = "center_horizontal"
android: textSize = "18dp"
android: layout_height = "wrap_content" />
In Activity call as follows:
mAdapter = new MessageArrayAdapter (this, R.layout.list_view1_item, mListItems);
/ / You can also just use setListAdapter (mAdapter)
actualListView.setAdapter (mAdapter);
Custom ArrayAdapter code is as follows:
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.com.ccxe.bean.Article;
import cn.com.ccxe.bean.ComplexMessage;
import cn.com.ccxe.message.R;
import cn.com.ccxe.util.AsyncImageLoaderTask;
public class MessageArrayAdapter extends ArrayAdapter{
private int resourceId;
Context mContext;
LayoutInflater mLayoutInflater;
public MessageArrayAdapter (Context context, int textViewResourceId, Listcms) {
super (context, textViewResourceId, cms);
this.resourceId = textViewResourceId;
mContext = context;
mLayoutInflater = LayoutInflater.from (context);
}
@ Override
public View getView (int position, View convertView, ViewGroup parent) {
ComplexMessage cm = getItem (position);
View view;
if (convertView == null) {
view = mLayoutInflater.inflate (resourceId, parent, false);
} Else {
view = convertView;
}
LinearLayout linearLayout = (LinearLayout) view.findViewById (R.id.messageArrayAdapterLinerlayout);
Article [] arts = cm.getNews () getArticles ();.
if (arts! = null && arts.length == 1) {
/ / If there is only one message
} Else {
/ / If multiple messages
for (int i = 0; iif (i == 0) {
Article art = arts [i];
ImageView iv = (ImageView) view.findViewById (R.id.image_complexMessageTitle);
iv.setMinimumWidth (linearLayout.getWidth () -10);
iv.setMinimumHeight ((linearLayout.getWidth () -10) / 2);
new AsyncImageLoaderTask () execute (art.getPicurl (), iv);.
TextView tv1 = (TextView) view.findViewById (R.id.txt_name);
tv1.setText (art.getTitle ());
} Else {
}
}
}
return view;
}
}
Now this case is the normal display of data in the database.
But just based list_view1_item.xml set a fixed display in a picture with VIEWTEXT,
If you want to dynamically add some VIEW Linerlayout ID for messageArrayAdapterLinerlayout in
If the getView method to generate the following section through JAVA code:
eLayout frameLayout = new FrameLayout (mContext);
FrameLayout.LayoutParams frameLayoutParams = new FrameLayout.LayoutParams (FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
frameLayoutParams.leftMargin = 20;
frameLayoutParams.rightMargin = 20;
frameLayout.setLayoutParams (frameLayoutParams);
ImageView iv = new ImageView (mContext);
android.view.ViewGroup.LayoutParams ivLayoutParams = new android.view.ViewGroup.LayoutParams (linearLayout.getWidth (), linearLayout.getWidth () / 2);
iv.setLayoutParams (ivLayoutParams);
iv.setTag (art.getPicurl ());
new AsyncImageLoaderTask () execute (art.getPicurl (), iv);.
TextView tv = new TextView (mContext);
android.view.ViewGroup.LayoutParams tvLayoutParams = new android.view.ViewGroup.LayoutParams (linearLayout.getWidth (), linearLayout.getWidth () / 4);
tv.setLayoutParams (tvLayoutParams);
tv.setText (art.getTitle ());
frameLayout.addView (iv);
frameLayout.addView (tv);
linearLayout.addView (frameLayout);
, But do not show up, please advice?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
This is to imitate the kind of news and information interface micro-channel public platform, but also how to fake unsuccessful. Please people pointing.
Reply:
A key forwards a key forwards a key forwards a key forwards
No comments:
Post a Comment