如何在每个标签上显示不同的TextView(每个标签都有自己的数据) 示例:如果我的数据库为空并开始输入我的名称_地方 显示:选项卡1 =仅从ID_1获取NAME_PLACE,选项卡2 = ID_2,选项卡3 =来自数据库的ID_3 然后,如果我在tab1上改写以更改Name_Place选项卡1 = ID_1只需更改id 1更改或行 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, { {0}}
public class DataBaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "big.db";
public static final String TABLE_NAME = "images";
public static final String NAME = "name";
public static final String PLACE = "place";
public static final String KEY_ID = "id";
public DataBaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
SQLiteDatabase db = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_IMAGES_TABLE = "CREATE TABLE images ( " +
"ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
"name TEXT, " +
"place TEXT )";
db.execSQL(CREATE_IMAGES_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS images");
this.onCreate(db);
}
public void insertentry(String name, String place) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(NAME, name);
contentValues.put(PLACE, place);
db.insert(TABLE_NAME, null, contentValues);
db.close();
}
public DbResponse getData() {
DbResponse obj = new DbResponse();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from " + TABLE_NAME, null);
if (cursor.getCount() > 0) {
cursor.moveToNext();
obj.name = cursor.getString(cursor.getColumnIndex(NAME));
obj.place = cursor.getString(cursor.getColumnIndex(PLACE));
}
cursor.close();
return obj;
}
}
TAb1类:每个类都有相同的代码
public class Tab1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab1, container, false);
ImageView imageView = (ImageView) v.findViewById(R.id.img1);
String photoPath = Environment.getExternalStorageDirectory() + "/Download/image1.jpg";
Bitmap bitmap1 = BitmapFactory.decodeFile(photoPath);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
final Bitmap b = BitmapFactory.decodeFile(photoPath, options);
DataBaseHelper db = new DataBaseHelper(getActivity());
DbResponse response = db.getData();
TextView textView = (TextView)v.findViewById(R.id.txt3);
textView.setText(response.name+" - "+response.place);
imageView.setImageBitmap(b);
return v;
}
}