0
因此,我有這個類顯示數據庫內部和應用程序,我想知道是否有可能將一個滾動條放入應用程序中,以便在數據庫變得太大而無法使用屏幕時可以簡單地向下滾動顯示錶格中的所有元素?Android數據庫滾動條
以下是此類的代碼
package com.example.app;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class CurrentBets extends Activity {
private String fname,lname,email;
private Button button;
SQLiteDatabase db;
TableRow tableRow;
TextView textView,textView1,textView2,textView3,textView4,textView5;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_current_bets);
db=openOrCreateDatabase("MyDB1",MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Student(fname VARCHAR,lname VARCHAR,email VARCHAR);");
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(),
"Bet Was Added", Toast.LENGTH_LONG).show();
}
});
}
public void data(View view)
{
EditText edittext1=(EditText)findViewById(R.id.firstname);
EditText edittext2=(EditText)findViewById(R.id.lastname);
EditText edittext3=(EditText)findViewById(R.id.email);
fname=edittext1.getText().toString();
lname=edittext2.getText().toString();
email=edittext3.getText().toString();
db.execSQL("INSERT INTO Student VALUES('"+fname+"','"+lname+"','"+email+"');");
}
public void showdata(View view)
{
Cursor c=db.rawQuery("SELECT * from Student", null);
int count= c.getCount();
c.moveToFirst();
TableLayout tableLayout = new TableLayout(getApplicationContext());
tableLayout.setVerticalScrollBarEnabled(true);
TableRow tableRow;
TextView textView,textView1,textView2,textView3,textView4,textView5;
tableRow = new TableRow(getApplicationContext());
textView=new TextView(getApplicationContext());
textView.setText("Stake");
textView.setTextColor(Color.RED);
textView.setTypeface(null, Typeface.BOLD);
textView.setPadding(20, 20, 20, 20);
tableRow.addView(textView);
textView4=new TextView(getApplicationContext());
textView4.setText("Odds");
textView4.setTextColor(Color.RED);
textView4.setTypeface(null, Typeface.BOLD);
textView4.setPadding(20, 20, 20, 20);
tableRow.addView(textView4);
textView5=new TextView(getApplicationContext());
textView5.setText("Returns");
textView5.setTextColor(Color.RED);
textView5.setTypeface(null, Typeface.BOLD);
textView5.setPadding(20, 20, 20, 20);
tableRow.addView(textView5);
tableLayout.addView(tableRow);
for (Integer j = 0; j < count; j++)
{
tableRow = new TableRow(getApplicationContext());
textView1 = new TextView(getApplicationContext());
textView1.setText(c.getString(c.getColumnIndex("fname")));
textView2 = new TextView(getApplicationContext());
textView2.setText(c.getString(c.getColumnIndex("lname")));
textView3 = new TextView(getApplicationContext());
textView3.setText(c.getString(c.getColumnIndex("email")));
textView1.setPadding(20, 20, 20, 20);
textView2.setPadding(20, 20, 20, 20);
textView3.setPadding(20, 20, 20, 20);
tableRow.addView(textView1);
tableRow.addView(textView2);
tableRow.addView(textView3);
tableLayout.addView(tableRow);
c.moveToNext() ;
}
setContentView(tableLayout);
db.close();
}
public void close(View view)
{
System.exit(0);
}
}