カスタムリストビューがあります。Webサーバーからのデータを表示する必要があります。EditText からの入力に基づいて検索を実装する必要があります。ListView の各行には、画像、タイトル、およびメッセージが含まれます。WebServer からの応答に基づいて画像が変化します。コードを見てください。
class CustomListView extends ArrayAdapter {
Context context;
LayoutInflater mInflater;
ArrayList<PostData> mPostingData = null;
private Bitmap mIcon1;
private Bitmap mIcon2;
private Bitmap mIcon3;
PostData mp ;
public CustomListView(Context c)
{
super(c, 0);
mInflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mIcon1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.text_icon);
mIcon2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.image_icon);
mIcon3 = BitmapFactory.decodeResource(c.getResources(), R.drawable.video_icon);
}
public int getCount() {
// TODO Auto-generated method stub
if(mPostingData!=null){
return mPostingData.size();
}else{
return 0;
}
}
public void setData(ArrayList<PostData> mPpst) {
mPostingData = mPpst;
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
///int type = getItemViewType(arg0);
Log.i("Aru","get View");
if(mPostingData == null ){
return null;
}
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listviewimg, null);
convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.ll=(LinearLayout) convertView.findViewById(R.id.lvid);
holder.text = (TextView) convertView.findViewById(R.id.texttitle);
holder.text2 = (TextView) convertView.findViewById(R.id.tvst);
holder.icon = (ImageView) convertView.findViewById(R.id.llimage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
mp = mPostingData.get(position);
String title = mp.mType;
if(mp.mTitle!=null && Name.equals(mp.mPostedBy )){
title = mp.mTitle+" "+title;
//holder.text.setBackgroundColor(Color.WHITE);
holder.ll.setBackgroundResource(R.drawable.listbkgme);
holder.text.setText(title);
}
else if(mp.mTitle!=null && Name!=mp.mPostedBy)
{
title = mp.mTitle+" "+title;
holder.text.setText(title);
}
if(mp.mMessage!=null && Name.equals(mp.mPostedBy )){
holder.ll.setBackgroundResource(R.drawable.listbkgme);
holder.text2.setText(mp.mMessage);
}
else if(mp.mMessage!=null && Name!=(mp.mPostedBy))
{
holder.text2.setText(mp.mMessage);
}
if(mp.mImageUrl!=null ){
holder.icon.setImageBitmap(mIcon2);
}else if(mp.mVideoUrl!=null){
holder.icon.setImageBitmap(mIcon3);
}else{
holder.icon.setImageBitmap(mIcon1);
}
return convertView;
}
class ViewHolder {
TextView text;
TextView text2;
ImageView icon;
LinearLayout ll;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
投稿データ クラス
class PostData {
String mID;
String mPostedBy;
String mTitle;
String mMessage;
String mImageUrl;
String mVideoUrl;
String mType ;
boolean me=false;
}
タイトルに基づく並べ替え。タイトルに基づいてリストビューを検索するにはどうすればよいですか??
search= (EditText) findViewById(R.id.searchbox);
search.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
final String searchString=search.getText().toString();
int textLength=searchString.length();
Collections.sort(
mTempPost,
new Comparator<PostData>()
{
public int compare(PostData lhs, PostData rhs) {
System.out.println("........................"+lhs.mTitle+" "+rhs.mTitle);
return lhs.mTitle.compareTo(rhs.mTitle);
}
}
);
mCustomListView.notifyDataSetChanged();
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
// mCustomListView.notifyDataSetChanged();
}
});