public class MineActivity extends Activity {
private Toast toast;//在类前面声明吐司,确保在这个页面只有一个吐司
//需要谈吐司的地方调用showToast()
public void showToast() {
String msg = "请您先登录";
if (toast == null) {
toast = Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
} else {
toast.cancel();//关闭吐司显示
toast = Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
}
toast.show();//重新显示吐司
}
}
@Override
public int getCount() {
try {
return mList3.get(0).postNeirong.size();
} catch (Exception e) {
String msg="网络不通,请联网后重新尝试";
if (toast == null) {
toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
} else {
toast.cancel();//关闭吐司显示
toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
}
toast.show();//重新显示吐司
}
return 0;
}