2016-08-13 5 views
1

Android 앱에서 작업하고 있습니다. 앱 제목은 광고 제목, 광고 설명 및 광고 이미지 경로 (이미지 경로)와 같은 일부 광고 정보를 취하여 광고를 게시하는 것입니다. 많은 수 있습니다).하나의 항목으로 여러 이미지 경로를 영역 데이터베이스에 문자열로 저장

이 작업에는 영역 데이터베이스가 사용됩니다. 나는이 정보를 데이터베이스에 저장할 때 어려움을 겪고있다. 하나의 광고 항목으로 여러 이미지 경로를 저장하려면 어떻게해야합니까?

내 필드는 다음과 같습니다

Ad Title 
Ad Description 
Ad Image Path (Multi) 

이것은

public class FacebookAds extends RealmObject { 

@PrimaryKey 
@Index 
private int id; 
private String title; 
private String tags; 
private String description; 
private String imageName; // How to use this for multiple image Path 

public FacebookAds() { 

} 

public String getImageName() { 
    return imageName; 
} 

public void setImageName(String imageName) { 
    this.imageName = imageName; 
} 

public String getDescription() { 
    return description; 
} 

public void setDescription(String description) { 
    this.description = description; 
} 

public String getTags() { 
    return tags; 
} 

public void setTags(String tags) { 
    this.tags = tags; 
} 

public String getTitle() { 
    return title; 
} 

public void setTitle(String title) { 
    this.title = title; 
} 

public int getId() { 
    return id; 
} 

public void setId(int id) { 
    this.id = id; 
} 

}

This is my Ad new Title Dialog

답변

0

간단한 직관적 인 방법은 그들을 연결 한 다음 단일 문자열로 저장하는 것입니다. 검색을 원할 때 영역 데이터베이스에서 문자열을 가져 와서 분리 문자로 분할하면됩니다. 예를 들어

는 :

String imagePath1 = ... 
String imagePath2 = ... 

// Store this string 
String imagePath = imagePath1 + "|" + imagePath2; 

// Retrieve paths like this 
String[] paths = imagePath.split("|"); 

// imagePath1 
paths[0] 

// imagePath2 
paths[1] 
+0

굉장! Repo 때문에 투표 할 수는 없지만 당신을 위해 축복을합니다 :-) –

+0

그리고 태그에 관해서는 나중에이 태그를 검색 목적으로 사용합니까? –

+0

@ YasirAmeen 예, 태그에도 동일한 * 인코딩 * 메커니즘을 적용 할 수 있습니다. –

0

첫째 변환을주의 깊게 를 참조하십시오 내 RealmObject 클래스입니다 문자열과 바이트 배열 (바이트 [])이 될 수 없습니다 큰 16MB보다

영역 :이 ByteArray 내가 포기하고 데모

Bitmap bmp = intent.getExtras().get("data"); 
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray(); 

다음 영역 데이터베이스

공지 사항으로 바이트 []을 저장에 이미지 boolean, byte, short, "none", long, float, double, String, Date 및 byte []와 같은 필드 유형을 지원합니다. 정수 유형 byte, short, int 및 long은 모두 Realm 내에서 동일한 유형 (실제로는 long)으로 매핑됩니다. 또한 RealmObject 및 RealmList의 하위 클래스가 모델 관계를 지원합니다.

+0

대답 해 주셔서 감사합니다,하지만 난 문자열로 여러 이미지 경로를 저장할. 내 질문을 편집했습니다 –

+0

이 예제를 참조로 사용하십시오. –

+0

http://www.androidhive.info/2016/05/android-working-with-realm-database-replacing-sqlite-core-data/ –

관련 문제