からデータベースを表示する:)つのアクティビティからデータを渡し、主な活動
私が直面してる問題は、私はをクリックするだけで、主な活動からデータベースを表示することができませんということですボタン。データベース内のデータは別のアクティビティから渡されています。何か不足しているかどうか、またはこれを修正する方法を知りたいと思います。感謝:)
(メソッドのonCreate後に主な活動に使用されている)
MainActivity
public void displayDataInTable() {
roomDatabase myOpenHelper;
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String status = bundle.getString("status");
String roomValue =bundle.getString("roomValue");
//List for the name of the players and their scores
List<String> roomNumber = new ArrayList<String>();
List<String> roomStatus = new ArrayList<String>();
//The data being read from the database
myOpenHelper = new roomDatabase(this, DATABASE_NAME, null, VERSION_NUMBER);
SQLiteDatabase db = myOpenHelper.getReadableDatabase();
Cursor cursor = db.query(roomDatabase.TABLE_NAME, null, null, null, null, null,null,null);
//The name and the score is printed on the row of the list
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String roomValueA = cursor.getString(cursor.getColumnIndex("roomValue"));
String statusA = cursor.getString(cursor.getColumnIndex("status"));
roomNumber.add(roomValueA);
roomStatus.add(" Recipe Ordered " + statusA);
}
//The items to de displayed are sent to the AdapterB
if ((roomNumber != null) && (roomStatus != null)) {
AdapterB adapter = new AdapterB(this, roomNumber, roomStatus);
setListAdapter(adapter);
}
}
LogsActivity
public class LogsActivity extends ListActivity{
roomDatabase myOpenHelper;
final String DATABASE_NAME = "roomstatus.db";
final int VERSION_NUMBER = 1;
ContentValues values1 = new ContentValues();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//variables are extracted from the bundle
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String status = bundle.getString("status");
String roomValue = bundle.getString("roomValue");
myOpenHelper = new roomDatabase(this, DATABASE_NAME, null, VERSION_NUMBER);
SQLiteDatabase db = myOpenHelper.getWritableDatabase();
values1.put("status", status);
values1.put("roomValue", roomValue);
Toast.makeText(LogsActivity.this, status, Toast.LENGTH_LONG).show();
//Data is entered into the table
db.insert(roomDatabase.TABLE_NAME, null, values1);
Intent newIntentBundle = new Intent(LogsActivity.this, MainActivity.class);
Bundle bundleA = new Bundle();
bundle.putString("status", status);
bundle.putString("roomValue", roomValue);
newIntentBundle.putExtras(bundle);
startActivity(newIntentBundle);
}
}
NOTE - 私は承知していますこれは正しい方法ではないかもしれませんそれはメインアクティビティで新しいデータベースを作成し、アダプタに問題があることを意味するので、どんな助けにも感謝します。 :)
パスデータバンドルを介して基準については、このhttp://stackoverflow.com/questions/15445182/passing-data-from-one-activity-to-another-using-bundle-not-displaying-in-secon – rookieDeveloper