我在铺设吐司时没什么问题。 我有四项活动,其中三项活动不应开放,直至第四项活动 设置未完成。
在主要活动中,我有四个文字点击这些我想要得到那个活动 但在此之前我正在检查设置表..这是在第四个活动..第一个完成设置然后只有你去其他活动。这就是为什么我要显示吐司请 完成设置First.Below代码检查是设置表是空的。但是第一次点击text1消息不显示。但是当我去第四个活动然后回到main然后它显示toast.If任何人问题那么请让我知道
text1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{ // TODO Auto-generated method stub
try
{
NewNewDataHelper db=new NewNewDataHelper(this);
List<String> list=db.CheckSettingData();
if(db.CheckSettingData().isEmpty())
{
showCustomSelectState();
}else
{
Intent i =new Intent(MainActivity.this,Log_Practice_timeActivity.class);
i.putExtra("s11","Log");
startActivity(i);
}
}catch(Exception e)
{
}
}
});
text4.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
Intent i =new Intent(MainActivity.this,SettingActivity.class);
startActivity(i);
}
});
Toast Message方法:
public void showCustomSelectState()
{
msg="Please Complete Setting First";
LayoutInflater inflater = getLayoutInflater();
//Inflate the Layout
View layout = inflater.inflate(R.layout.my_custom_toast1 (ViewGroup)findViewById(R.id.custom_toast_layout));
TextView text = (TextView) layout.findViewById(R.id.textToShow);
// Set the Text to show in
TextView text.setText(msg);
Toast toast = new Toast(MainActivity.this);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
My DataHelper Class And In this CheckSettingData Method is available
> public class NewNewDataHelper
{
private Context context;
private SQLiteDatabase db;
NewNewOpenHelper myDbHelper;
// Constructor to accept class instance in on click method.
public NewNewDataHelper(OnClickListener onClickListener)
{
// TODO Auto-generated constructor stub
this.context=context;
myDbHelper = new NewNewOpenHelper(this.context);
try
{
myDbHelper.createDataBase();
}
catch (IOException ioe)
{
ioe.printStackTrace();}
}
}
public List<String>CheckSettingData()
{
this.db=myDbHelper.getDatabase();
String strValue=null;
String strValue1=null;
String strValue2=null;
String strValue3=null;
Cursor c=null;
ArrayList<String> ar=new ArrayList<String>();
//Log.w("NewNewDataHelper", "param "+param);
c=db.rawQuery("SELECT * from tb_settings",null);
//Log.w("NewNewDataHelper", "c= "+c);
if(c!=null)
{
//Log.w("NewNewDataHelper", "Inside IF");
if(c.moveToFirst())
{
do
{
strValue=c.getString(c.getColumnIndex("state"));
strValue1=c.getString(c.getColumnIndex ("email_id"));
strValue2=c.getString(c.getColumnIndex("active_flag"));
strValue3=c.getString(c.getColumnIndex("create_date"));
String str=strValue+"~"+strValue1+"~"+strValue3+"~"+strValue3;
//Log.w("strValue=", strValue);
ar.add(str);
}
while(c.moveToNext());
}
}
c.close();
db.close();
myDbHelper.close();
return ar;
}
}
答案 0 :(得分:2)
// try this way
public void showCustomSelectState()
{
String msg="Please Complete Setting First";
View layout = LayoutInflater.from(this).inflate(R.layout.my_custom_toast1,null,false);
TextView text = (TextView) layout.findViewById(R.id.textToShow);
text.setText(msg);
Toast toast = new Toast(this);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
答案 1 :(得分:0)
试试这个,
public void showCustomSelectState()
{
String msg="Please Complete Setting First";
//Inflate the Layout
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.my_custom_toast1, null);
TextView text = (TextView) layout.findViewById(R.id.textToShow);
// Set the Text to show in
TextView text.setText(msg);
Toast toast = new Toast(MainActivity.this);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
答案 2 :(得分:0)
在你搬到第四个活动之前,是否有可能, 此代码中的某些值导致异常。 (应用程序不会因为你抓到它而崩溃)
NewNewDataHelper db=new NewNewDataHelper(this);
List<String> list=db.CheckSettingData();
if(db.CheckSettingData().isEmpty())
尝试在catch块中提供错误消息
也许你的CheckSettingData()
在你第一次实例化第四个活动之前返回null。您可以使用CheckSettingData()