// All required Imports
public class PuzzleActivity extends Activity implements OnClickListener{
private PuzzlerDB db;
private Puzzle puz;
private int puzId=1;
private String puzAns="";
private int score=0;
private TextView tvPuzContent;
private EditText etPuzAns;
private Button btnCheck;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_puzzle);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
}
db = new PuzzlerDB(this);
puz = db.getPuzzle(puzId);
puzAns = puz.getAnswer();
tvPuzContent = (TextView) findViewById(R.id.tv_puz_content);
tvPuzContent.setText(puz.getContent());
btnCheck = (Button) findViewById(R.id.btn_check);
btnCheck.setOnClickListener(this);
android.util.Log.v("IN SIDE ACTIVITY: ", "id: "+ puzId + " answer: "+puz.getAnswer());
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_check:
checkAndNotify(puzAns);
break;
}
}
private void checkAndNotify(String puzAns)
{
String ans = ((EditText)findViewById(R.id.te_puz_ans)).getText().toString();
if(ans.trim().equalsIgnoreCase(puzAns.trim()))
{
//show pop-up dialog for right answer
new AlertDialog.Builder(this).setTitle("The Puzzler:")
.setMessage("Wow! Right Answer!!")
.setNeutralButton("Continue", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dlg, int sumthin)
{
android.util.Log.v("IN SIDE function:", " onClick of Dialog");
update();
}
}).show();
}else{
new AlertDialog.Builder(this).setTitle("The Puzzler:")
.setMessage("Sorry! You have to rethink!!")
.setNeutralButton("Continue", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dlg, int sumthin)
{
// do nothing – it will close on its own
}
}).show();
}
}
protected void update() {
score = score + 10;
++puzId;
}
@Override
protected void onResume() {
super.onResume();
setContentView(R.layout.activity_puzzle);
puz = db.getPuzzle(puzId);
if(puz != null)
{
tvPuzContent.setText(puz.getContent());
android.util.Log.v("IN SIDE onResume:", " Content: "+ puz.getContent());
puzAns = puz.getAnswer();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
db.close();
}
}
활동 레이아웃은 다음과 같습니다 DB를 쿼리가 제대로 내용을 반환TextView의 setText()가 다음 코드에서 작동하지 않는 이유는 무엇입니까? 다음과 같이
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bgimg"
android:layout_gravity="center">
<TableLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="20dp"
android:stretchColumns="*">
<TableRow>
<TextView android:id="@+id/tv_puz_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:typeface="serif"
android:textStyle="bold"
android:textSize="20sp"
android:text="" />
</TableRow>
<TableRow>
<EditText android:id="@+id/te_puz_ans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_span="3"
android:hint="Answer" />
</TableRow>
<TableRow android:gravity="center">
<Button android:id="@+id/btn_check"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:hint="Check" />
<Button android:id="@+id/btn_skip"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:hint="Skip" />
<Button android:id="@+id/btn_hint"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:hint="Hint" />
</TableRow>
</TableLayout>
</LinearLayout>
내가 로그 캣을 통해 확인할 수있다. 하지만 텍스트보기가 나타나지 않습니다. EditText 및 단추가 표시되고 있습니다.
나는 텍스트 뷰의 정적 (ⅱ) 문자열의 퍼즐 콘텐츠를 수신 한 후 성공하지의 setText()와 다른 것들을 통해 설정하기 (I)와 같은 다른 게시물에서 다양한 옵션을 시도했습니다. pls, 이것에 대한 해결책을 제안하십시오.
는 PUZ var에 뭔가를 얻었다? – Saqib
이 로그에 뭐가 들었습니까? android.util.Log.v ("IN 사이드 onResume :", "Content :"+ puz.getContent()); – pozuelog
예. puz는 모든 데이터 멤버의 가치를 가지고 있습니다. 22 '01 -23 : 28 : 17.937 : V/SIDE onResume IN : (18673) : 내용 : 2 × 5의 값이 무엇 그리고 나는 등 이상 로그에 퍼즐의 내용을 무엇입니까 – Dexter