我想使用 tablerow 在警报对话框中显示我的表 sql,并在
main.javainflater
中手动创建表score.xml
//table3
Cursor gethighscorealter=highscoreDB.rawQuery("SELECT*FROM HIGHSCORE3"+
" ORDER BY TIME asc, MOVE asc ;"
, null);
if(gethighscorealter.getCount()>0){
gethighscorealter.moveToFirst();
timer= gethighscorealter.getLong(gethighscorealter.getColumnIndex("TIME"));
move = gethighscorealter.getInt(gethighscorealter.getColumnIndex("MOVE"));
grid = gethighscorealter.getInt(gethighscorealter.getColumnIndex("GRID"));
textView31.setText(""+timer);
textView32.setText(""+move);
textView33.setText(""+grid);
}else{
//textView31.setText("-");textView32.setText("-");textView33.setText("-");
}
分数.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table_score"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:selectable="false"
android:focusable="false"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:singleLine="true"
android:text="TIME"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="MOVE"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="GRID"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:selectable="false"
android:focusable="false"
>
<TextView
android:id="@+id/textView31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:singleLine="true"
android:text="TIME"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView32"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="MOVE"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="GRID"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</TableRow>
日志猫
06-21 14:05:03.169: E/AndroidRuntime(1504): FATAL EXCEPTION: main
06-21 14:05:03.169: E/AndroidRuntime(1504): java.lang.NullPointerException
06-21 14:05:03.169: E/AndroidRuntime(1504): at skripsi.slidame.PuzzleActivity.highscore(PuzzleActivity.java:280)
06-21 14:05:03.169: E/AndroidRuntime(1504): at skripsi.slidame.PuzzleActivity.onOptionsItemSelected(PuzzleActivity.java:143)
06-21 14:05:03.169: E/AndroidRuntime(1504): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
java:280 应该是textView31.setText(""+timer);
当我用 toast 检查计时器时我得到了值
它认为我得到了 nullexceptiontextview
创建方法
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//db
String DB_PATH= getApplicationContext().getFilesDir().getPath();
highscoreDB = SQLiteDatabase.openDatabase(DB_PATH+slidameBoard.DB_NAME,null,SQLiteDatabase.CREATE_IF_NECESSARY);
new countleft(START_DELAY, INTERVAL);
//sensor
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this,sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);
//lebar
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
wm.getDefaultDisplay().getMetrics(displayMetrics);
lebar = displayMetrics.widthPixels;
setContentView(R.layout.activity_slidame4);
textView31 = (TextView)findViewById(R.id.textView31);
textView32 = (TextView)findViewById(R.id.textView32);
textView33 = (TextView)findViewById(R.id.textView33);
textView41 = (TextView)findViewById(R.id.textView41);
textView42 = (TextView)findViewById(R.id.textView42);
textView43 = (TextView)findViewById(R.id.textView43);
}
膨胀法
AlertDialog.Builder showhighscore =new AlertDialog.Builder(this);
LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.score, null);//score
showhighscore.setCancelable(false);
showhighscore.setTitle(" ");
showhighscore.setView(layout);
showhighscore.setIcon(R.drawable.menu_icon);
showhighscore.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
onResume();
}
});
showhighscore.show();