Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/05/2015, 21:27
camill
 
Fecha de Ingreso: mayo-2015
Mensajes: 3
Antigüedad: 9 años, 6 meses
Puntos: 0
Respuesta: Aplicación tipo test/android

gracias por responder ipraetoriux!!!......ojalá puedas ayudarme...este es mi código:

public class DbHelper extends SQLiteOpenHelper{

private static final String DB_NAME = "questions.sqlite";
private static final int DB_SCHEME_VERSION = 1;

public DbHelper(Context context) {
super(context, DB_NAME, null, DB_SCHEME_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {

db.execSQL(DataBaseManager.CREATE_TABLE);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}

DataBaseManager.class

public class DataBaseManager {
public static final String TABLE_NAME = "Questions";

public static final String CN_ID = "_id";
public static final String CN_QUESTION = "question";
public static final String CN_A1 = "a1";
public static final String CN_A2 = "a2";
public static final String CN_A3 = "a3";
public static final String CN_A4 = "a4";
public static final String CN_A5 = "a5";
public static final String CN_AC = "ac";

public static final String CREATE_TABLE = "create table " + TABLE_NAME + "("
+ CN_ID + " integer primary key autoincrement,"
+ CN_QUESTION + "text,"
+ CN_A1 + " text,"
+ CN_A2 + " text,"
+ CN_A3 + " text,"
+ CN_A4 + " text,"
+ CN_A5 + " text,"
+ CN_AC + " text);";

private DbHelper helper;
private SQLiteDatabase db;

public DataBaseManager(Context context)
{
helper = new DbHelper(context);
db = helper.getWritableDatabase();
}

public ContentValues generateContentValues(String question, String a1, String a2, String a3, String a4, String a5, String ac)

{
ContentValues values = new ContentValues();
values.put(CN_QUESTION, question);
values.put(CN_A1, a1);
values.put(CN_A2, a2);
values.put(CN_A3, a3);
values.put(CN_A4, a4);
values.put(CN_A5, a5);
values.put(CN_AC, ac);

return values;
}

public void insert(String question, String a1, String a2, String a3, String a4, String a5, String ac) {


db.insert(TABLE_NAME, null, generateContentValues(question,a1,a2,a3,a4,a5,ac)) ;
}

public Cursor chargeCursorQuestions() {
String[] columns = new String[]{CN_ID,CN_QUESTION,CN_A1,CN_A2,CN_A3,CN_A4,CN_A5,C N_AC};
return db.query(TABLE_NAME,columns,null,null,null,null,nu ll);
}
}

MainActivity.class

public class MainActivity extends ActionBarActivity {

private DataBaseManager manager;
private Cursor cursor;
private ListView list;
private SimpleCursorAdapter adapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

manager = new DataBaseManager(this);
list = (ListView) findViewById(R.id.listView);
manager.insert("1. ¿what is my name?", "a) Jhonn", "b) Joseph", "c) Ross", "d) Camil", "e) Gunter", "D) CAMIL");

String[] from = new String[]{manager.CN_QUESTION, manager.CN_A1, manager.CN_A2, manager.CN_A3, manager.CN_A4, manager.CN_A5, manager.CN_AC};
int[] to = new int[] {android.R.id.text1};

cursor = manager.chargeCursorQuestions();
adapter = new SimpleCursorAdapter(this,android.R.layout.simple_l ist_item_1,cursor,from,to,0);
list.setAdapter(adapter);

}