public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_login:
//执行点击后的操作
break;
}
}
btn_login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//执行点击后的操作
}
});
protected Context mContext;
protected List<T> mValues;
protected LayoutInflater mInflater;
public ListBaseAdapter(Context context, List<T> values) {
mContext = context;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mValues = values;
}
public Context getContext() {
return mContext;
}
@Override
public int getCount() {
if (mValues != null)
return mValues.size();
return 0;
}
@Override
public T getItem(int position) {
if (position == getCount() - 1 || mValues == null) {
return null;
}
return mValues.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getItemView(convertView, position);
}
protected abstract View getItemView(View convertView, int position);
public void update(List<T> values) {
mValues = values;
notifyDataSetInvalidated();
notifyDataSetChanged();
}
}
* 将字符转换成数字
* @param value
* @param defaultValue
* @return
*/
public final static int convertToInt(String value,int defaultValue){
if(StringUtils.isNullOrEmpty(value)){
return defaultValue;
}
try {
return Integer.valueOf(value.toString());
} catch (Exception e) {
try {
return Double.valueOf(value.toString()).intValue();
} catch (Exception e1) {
return defaultValue;
}
}
}
* 判断是否为空
*
* @param text
* @return
*/
public static boolean isNullOrEmpty(String text) {
if (text == null || "".equals(text.trim()) || text.trim().length() == 0
|| "null".equals(text.trim())) {
return true;
} else {
return false;
}
}