listView 的Adapter重写满足listview加载多项

package health.week;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

class ListViewInfo{
int image;
String text1;
String text2;
}
public class HEALTH_WEEKActivity extends Activity {
/** Called when the activity is first created. */
TextView newDate ;
TextView Week ;
TextView oldDate ;
TextView festival ;
TextView Location ;
String newDateString = null;
String ClockString = null;
String WeekString = null;
String oldDateString = null;
String festivalString = null;
GridView Menu = null;
ListView Function = null;
ImageButton mySave ;
ImageButton fristpage ;
ImageButton setting;
ImageButton history;
ImageButton quit ;
ArrayList<HashMap<String,Object>> functionGrid;
ArrayList<ListViewInfo> functionList;
HashMap<String,Object> tempHashMap = null;
ListViewInfo listViewInfo = null;
SimpleAdapter gridAdapter;
ListAdapter listAdapter;
Calendar getNewDate;
boolean systemTimeThreadStatus = true;
final static String[] weekList = new String[]{"周日","周一","周二","周三","周四","周五","周六"};
final static String chineseNumber[] = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//------------------界面处理(加载)--------------------------
newDate = (TextView)this.findViewById(R.id.newdate);
oldDate = (TextView)this.findViewById(R.id.olddate);
Week = (TextView)this.findViewById(R.id.week) ;
festival= (TextView)this.findViewById(R.id.qijie) ;
Location= (TextView)this.findViewById(R.id.location);
Menu = (GridView)this.findViewById(R.id.gridView1);
Function= (ListView)this.findViewById(R.id.function);
fristpage=(ImageButton)this.findViewById(R.id.fristpage);
mySave = (ImageButton)this.findViewById(R.id.mysave);
history = (ImageButton)this.findViewById(R.id.history);
setting = (ImageButton)this.findViewById(R.id.setting);
quit = (ImageButton)this.findViewById(R.id.quit);
//-------------------界面配置--------------------------------
functionGrid = new ArrayList<HashMap<String,Object>>();
tempHashMap = new HashMap<String, Object>();
tempHashMap.put("Name", "食物相克");
tempHashMap.put("Image", R.drawable.ic_launcher);
functionGrid.add(tempHashMap);
tempHashMap = new HashMap<String, Object>();
tempHashMap.put("Name", "四季靓汤");
tempHashMap.put("Image", R.drawable.ic_launcher);
functionGrid.add(tempHashMap);
tempHashMap = new HashMap<String, Object>();
tempHashMap.put("Name", "拉伸除疲");
tempHashMap.put("Image", R.drawable.ic_launcher);
functionGrid.add(tempHashMap);
tempHashMap = new HashMap<String, Object>();
tempHashMap.put("Name", "物件好用处");
tempHashMap.put("Image", R.drawable.ic_launcher);
functionGrid.add(tempHashMap);
gridAdapter = new SimpleAdapter(this,functionGrid,R.layout.gridview,new String[]{"Name","Image"},new int[]{R.id.gridtextView,R.id.gridimageView});
functionList = new ArrayList<ListViewInfo>();
listViewInfo = new ListViewInfo();
listViewInfo.image = R.drawable.ic_launcher;
listViewInfo.text1 = "食物相克:";
listViewInfo.text2 = "........................" +
"................................." +
"................................";
functionList.add(listViewInfo);
listViewInfo = new ListViewInfo();
listViewInfo.image = R.drawable.ic_launcher;
listViewInfo.text1 = "四季靓汤:";
listViewInfo.text2 = "........................" +
"................................." +
"................................";
functionList.add(listViewInfo);
listViewInfo = new ListViewInfo();
listViewInfo.image = R.drawable.ic_launcher;
listViewInfo.text1 = "拉伸除疲:";
listViewInfo.text2 = "........................" +
"................................." +
"................................";
functionList.add(listViewInfo);
listViewInfo = new ListViewInfo();
listViewInfo.image = R.drawable.ic_launcher;
listViewInfo.text1 = "物件好用处:";
listViewInfo.text2 = "........................" +
"................................." +
"................................";
functionList.add(listViewInfo);
listAdapter = new ListAdapter(this);
Menu.setAdapter(gridAdapter);
Function.setAdapter(listAdapter);
fristpage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}
});
mySave.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}
});
history.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}
});
setting.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}
});
quit.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}
});
}

public final class ViewHolder {

public ImageView img;

public TextView title;

public TextView info;
}


class ListAdapter extends BaseAdapter{
private LayoutInflater mInflater;
ListAdapter(Context context){
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return functionList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null) {

holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.listview, null);
holder.img = (ImageView) convertView.findViewById(R.id.listimageView);
holder.title = (TextView) convertView.findViewById(R.id.listtextView1);
holder.info = (TextView) convertView.findViewById(R.id.listtextView2);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.img.setImageDrawable(getResources().getDrawable(functionList.get(position).image));
holder.title.setText((String) functionList.get(position).text1);
holder.info.setText((String) functionList.get(position).text2);
return convertView;
}
}
}

 

 

//-------------------layout布局for listview---------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >

<ImageView
android:id="@+id/listimageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent" >

<TextView
android:id="@+id/listtextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="TextView" />

</RelativeLayout>

</LinearLayout>

</RelativeLayout>

<RelativeLayout
android:id="@+id/relativeLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/listtextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="TextView" />

</RelativeLayout>

</LinearLayout>

//----------------------------布局for gridview------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/gridimageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/gridtextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="TextView" />

</RelativeLayout>

</LinearLayout>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值