나는 안드로이드 개발과 stackoverflow에 새로운 브랜드이므로 제발 쉽게 가보겠습니다. ;)String이 TextView를 사용하여 예상 한 문자열 일 때
여러 개의 TextView가 포함 된 ViewGroup을 만들었습니다. 특히 케이스 상수가 내 Java 객체에 정의 된 정수인 스위치 케이스가 있습니다. 그런 다음 케이스 문을 String 값으로 생각하는 것으로 설정합니다. 마지막으로 setText() 메서드를 사용하여 TextView 객체를이 String으로 설정합니다. 내가 겪고있는 문제는 실제로보기로 반환되는 것은 텍스트 값이 아닌 대소 문자와 관련된 정수입니다. 이것은 내가 TextView에 전달하는 것이 int임을 믿게하지만, 나는 이것을 어떻게 수정할 수 있는지 보지 못한다.
도움을 주시면 감사하겠습니다.
뷰 그룹 코드는 여기에 있습니다 :
public View getView (int position, View convertView, ViewGroup parent)
{
ViewGroup listItem;
if (convertView == null) {
listItem = (ViewGroup) getLayoutInflator().inflate(R.layout.list_item, null);
}
else {
listItem = (ViewGroup) convertView;
}
MovieInfo movieInfo = list.get(position);
TextView movietitleText = (TextView) listItem.findViewById(R.id.movietitle_text);
TextView directorText = (TextView) listItem.findViewById(R.id.director_text);
TextView producerText = (TextView) listItem.findViewById(R.id.producer_text);
TextView releaseyearText = (TextView) listItem.findViewById(R.id.releaseyear_text);
TextView genreText = (TextView) listItem.findViewById(R.id.genre_text);
movietitleText.setText(movieInfo.getMovietitle());
producerText.setText(movieInfo.getProducer());
directorText.setText(movieInfo.getDirector());
releaseyearText.setText(movieInfo.getReleaseyear());
String genreName;
Resources resources = context.getResources();
switch (movieInfo.getGenre()) {
case MovieInfo.GENRE_ACTION:
genreName = resources.getString(R.string.action_label);
break;
case MovieInfo.GENRE_COMEDY:
genreName = resources.getString(R.string.comedy_label);
break;
case MovieInfo.GENRE_DRAMA:
genreName = resources.getString(R.string.drama_label);
break;
case MovieInfo.GENRE_FAMILY:
genreName = resources.getString(R.string.family_label);
break;
case MovieInfo.GENRE_HORROR:
genreName = resources.getString(R.string.horror_label);
break;
case MovieInfo.GENRE_ROMANCE:
genreName = resources.getString(R.string.romance_label);
break;
default:
case MovieInfo.GENRE_UNKNOWN:
genreName = resources.getString(R.string.unknown_label);
break;
}
genreText.setText(genreName);
return listItem;
}
상수 내 자바 여기 객체에 정의 된 경우 : 체크 상자를 선택하면
public static final int GENRE_UNKNOWN = 0;
public static final int GENRE_ACTION = 1;
public static final int GENRE_COMEDY = 2;
public static final int GENRE_DRAMA = 3;
public static final int GENRE_FAMILY = 4;
public static final int GENRE_HORROR = 5;
public static final int GENRE_ROMANCE = 6;
private String movietitle;
private String director;
private String producer;
private String releaseyear;
private int genre;
그리고 장르를 설정하는 작업이에 여기서 주요 활성 여기 strings.xml의
의if (actionCheckBox.isChecked()) movieInfo.setGenre(MovieInfo.GENRE_ACTION);
if (comedyCheckBox.isChecked()) movieInfo.setGenre(MovieInfo.GENRE_COMEDY);
if (dramaCheckBox.isChecked()) movieInfo.setGenre(MovieInfo.GENRE_DRAMA);
if (familyCheckBox.isChecked()) movieInfo.setGenre(MovieInfo.GENRE_FAMILY);
if (horrorCheckBox.isChecked()) movieInfo.setGenre(MovieInfo.GENRE_HORROR);
if (romanceCheckBox.isChecked()) movieInfo.setGenre(MovieInfo.GENRE_ROMANCE);
는
비중 :
<string name="movietitle_label">Movie Title</string>
<string name="director_label">Director</string>
<string name="producer_label">Producer</string>
<string name="releaseyear_label">Release Year</string>
<string name="genre_label">Genre</string>
<string name="action_label">Action</string>
<string name="comedy_label">Comedy</string>
<string name="drama_label">Drama</string>
<string name="family_label">Family</string>
<string name="horror_label">Horror</string>
<string name="romance_label">Romance</string>
<string name="unknown_label">Unknown</string>
<string name="ok_label">OK</string>
<string name="clear_label">Clear</string>
<string name="showdatabase_label">Show Database</string>
<string name="id_label">ID</string>
<string name="select">Select Year</string>
도움 주셔서 감사합니다.
내가 예를 들어 R.string.action_label 정말 문자열과 숫자가 아닌 경우 확인하려면 리소스 파일을 확인합니다. – Marcelo
위의 R.string에 strings.xml을 붙여 넣을 수 있습니까? (R.string.action_label 등) –
Marcelo, R.string.action_label 사실 int (public static final int action_label = 0x ####) 내 Strings.xml 파일에서 조치 . R이 자동으로 생성되고 action_label이 XML로 문자열로 정의 되었기 때문에 R에 어떻게 인식 할 수 있습니까? –
user2916836