Java.lang.integer to int:有可能吗?

时间:2015-11-01 22:58:13

标签: android

Java.lang.integer to int:有可能吗?

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.anatomi1);
    Dersadi=(TextView)findViewById(R.id.t_dersadi);
    Soru=(TextView)findViewById(R.id.t_soru);

    btncvp1 = (Button) findViewById(R.id.b_cvp1);
    btncvp2 = (Button) findViewById(R.id.b_cvp2);
    btncvp3 = (Button) findViewById(R.id.b_cvp3);
    btncvp4 = (Button) findViewById(R.id.b_cvp4);
    btncvp5 = (Button) findViewById(R.id.b_cvp5);

    btncvp1.setOnClickListener(this);
    btncvp2.setOnClickListener(this);
    btncvp3.setOnClickListener(this);
    btncvp4.setOnClickListener(this);
    btncvp5.setOnClickListener(this);

    db=openOrCreateDatabase("Soru", Context.MODE_PRIVATE, null);
    db.execSQL("CREATE TABLE IF NOT EXISTS sorular(id INTEGER PRIMARY KEY AUTOINCREMENT,ders VARCHAR,soru VARCHAR,cevap1 VARCHAR,cevap2 VARCHAR,cevap3 VARCHAR,cevap4 VARCHAR,cevap5 VARCHAR,puan VARCHAR);");
    Cursor c=db.rawQuery("SELECT * FROM sorular WHERE ders = 'Anatomi' ORDER BY RANDOM() LIMIT 1", null);
    List<Integer> btnlari = new ArrayList<>();
    for (int i = 3; i <= 7; i++)
    {
        btnlari.add(i);
    }
    Collections.shuffle(btnlari);
    pint1 = btnlari.get(1);
    pint2 = btnlari.get(2);
    pint3 = btnlari.get(3);
    pint4 = btnlari.get(4);
    pint5 = btnlari.get(5);
    if(c.moveToFirst())
    {
        Dersadi.setText(c.getString(1));
        Soru.setText(c.getString(2));
        btncvp1.setText(c.getString(pint1));
        btncvp2.setText(c.getString(pint2));
        btncvp3.setText(c.getString(pint3));
        btncvp4.setText(c.getString(pint4));
        btncvp5.setText(c.getString(pint5));
    }
}

我可以尝试在sql db中随机获取值但是java lang整数不可用吗?

任何人都可以帮我如何在按钮中随机获取sql db列吗?

1 个答案:

答案 0 :(得分:1)

您可以按如下方式解决此问题:

pint1 = btnlari.get(0);
pint2 = btnlari.get(1);
pint3 = btnlari.get(2);
pint4 = btnlari.get(3);
pint5 = btnlari.get(4);