您好我是创建自定义适配器的新手,我目前正在上大学。 我发现很难弄清楚为什么我的基础clase方法中的新Bmi(Bmi bmi)从未使用过。这是代码请看你能看到我做错了吗?非常感谢
public class BaseActivity extends AppCompatActivity
{
public int height;
public int weight;
public int bmiTotals = 0;
public static List<Bmi> bmis = new ArrayList<Bmi>();
public boolean newBmi(Bmi bmi) {
boolean nonValue = (height * weight) < 0;
if(!nonValue) {
if (height > 0 && weight > 0) {
int bm = height / 100;
int bn = weight;
bmiTotals = bn / (bm * bm);
bmis.add(bmi);
bmiTotals = bmi.bmiTotal;
} else {
Toast.makeText(this, "No values entered!", Toast.LENGTH_SHORT).show();
}
}
return nonValue;
}
///////////////////////////////////////This is in a separate class called Bmi
public class Bmi {
public int height;
public int weight;
public int bmiTotal;
public Bmi (int height, int weight, int bmiTotal)
{
this.height = height;
this.weight = weight;
this.bmiTotal = bmiTotal;
}
}
答案 0 :(得分:0)
试试这个,
public class SMSListAdapter extends BaseAdapter
{
private Context mContext;
Cursor cursor;
public SMSListAdapter(Context context,Cursor cur)
{
super();
mContext=context;
cursor=cur;
}
public int getCount()
{
// return the number of records in cursor
return cursor.getCount();
}
// getView method is called for each item of ListView
public View getView(int position, View view, ViewGroup parent)
{
// inflate the layout for each item of listView
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.listview_each_item, null);
// move the cursor to required position
cursor.moveToPosition(position);
// fetch the sender number and sms body from cursor
String senderNumber=cursor.getString(cursor.getColumnIndex("address"));
String smsBody=cursor.getString(cursor.getColumnIndex("body"));
// get the reference of textViews
TextView textViewConatctNumber=(TextView)view.findViewById(R.id.textViewSMSSender);
TextView textViewSMSBody=(TextView)view.findViewById(R.id.textViewMessageBody);
// Set the Sender number and smsBody to respective TextViews
textViewConatctNumber.setText(senderNumber);
textViewSMSBody.setText(smsBody);
return view;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
完整示例:http://www.learn-android-easily.com/2013/06/listview-with-custom-adapter.html