私は、あなたが "あなたのansは正しい"、 "あなたのansは間違っています"などの適切なメッセージをユーザが選択すると、クイズベースのアプリケーションを開発しています。トーストメッセージを表示する
1. how to display that sort of messages ?or is it the only way to display such msgs ?
2. If the user clicks wrong option the it should show the correct answer as well as the msg
here is what i have done so far but its not working giving force close!!!
public void onClick(View v)
{
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.button1:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right"))
{
displayAnswer();
}
else
{
errorAnswer();
}
break;
case R.id.button2:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right"))
{
displayAnswer();
}
else
{
errorAnswer();
}
break;
case R.id.button3:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right"))
{
displayAnswer();
}
else
{
errorAnswer();
}
break;
case R.id.button4:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right"))
{
displayAnswer();
}
else
{
errorAnswer();
}
break;
case R.id.btn_next:
// lyt_ans.setVisibility(View.GONE);
// lyt_quest.setVisibility(View.VISIBLE);
prev = counter;
counter += 1;
if (counter >= SIZE)
{
Collections.shuffle(quizIndexList);
counter = 0;
}
getInfoFromDB(quizIndexList.get(counter));
reLoad();
break;
case R.id.btn_bck:
getInfoFromDB(quizIndexList.get(prev));
reLoad();
// counter --;
}
}
private void errorAnswer()
{
Toast toast = new Toast(getApplicationContext());
toast.setDuration(SIZE);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setText("your answer is wrong");
// TODO Auto-generated method stub
}
private void displayAnswer() {
// TODO Auto-generated method stub
lyt_quest = (LinearLayout) findViewById(R.id.lyt_quest);
lyt_ans = (LinearLayout) findViewById(R.id.lyt_ans);
lyt_quest.setVisibility(View.VISIBLE);
lyt_ans.setVisibility(View.VISIBLE);
// TextView txt1 = null;
Toast toast = new Toast(getApplicationContext());
toast.setDuration(SIZE);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setText("Your answer is correct!!");
}
助けが必要です。
を参照してください? – Shubhayu
スタックトレースを添付する必要があります。トーストが表示されるようにするには 'Toast#show'を呼び出す必要があります。 'Toast#setDuration'は' LENGTH_SHORT'または 'LENGTH_LONG'でのみ呼び出すことができます。 – Qberticus
@Rithesh:toast.show()は –