Android EditTextView 中缺少文本
我做了一个应用程序,它将显示资产文件夹中的文本,我使用 EditText
来显示文本内容。测试我的应用程序文本在 HTC
Wildfire 中完美显示,而在 Samsung ACE
中,部分文本内容丢失。我真的不知道这可能是什么原因......
任何人都可以帮我解决这个问题吗?
编辑:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Intent extra = getIntent();
selectedBook = extra.getIntExtra("selectedbook", 0);
Log.v("selectedBook>>>>", ""+selectedBook);
selectedSection = extra.getIntExtra("selectedsection", 0);
Log.v("selectedSection>>>> ",""+ selectedSection );
contentTitle = extra.getStringExtra("contenttitle");
Log.v("contentTitle>>>> ",""+ contentTitle );
setContentView(R.layout.page);
layout = (LinearLayout)findViewById(R.id.layout);
view = (EditText) findViewById(R.id.text);
setTitleView();
setTextDisplay();
Spannable wordtoSpan = (Spannable) view.getText();
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
private void setTitleView() {
// TODO Auto-generated method stub
headingTitle = (TextView) findViewById(R.id.title_txt);
headingLbtn = (Button) findViewById(R.id.tbutton_left);
headingRbtn = (Button) findViewById(R.id.tbutton_right);
headingTitle.setText(contentTitle);
headingRbtn.setText("Bookmark");
headingLbtn.setText("Back");
headingLbtn.setVisibility(View.VISIBLE);
headingRbtn.setVisibility(View.VISIBLE);
headingLbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
headingRbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DbHelper db = new DbHelper(PageActivity.this);
db.addNote(selectedBook, selectedSection, contentTitle, "");
Toast.makeText(PageActivity.this, "Succesfully Bookmarked this section", Toast.LENGTH_SHORT).show();
}
});
}
private void setTextDisplay() {
try {
InputStream is = getAssets().open("" + selectedBook + ".txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
synchronized(this){
text = new String(buffer);
Log.v("WHOLETEXT",text);
Log.v("WHOLETEXT",""+text.length());
splitTxt = text.split("@abc@")[selectedSection];
}
String splitTxts[] = splitTxt.split("@xyz@");
Log.v("SPLITTEXT",""+splitTxts.length);
if(splitTxts.length!=1){
for(int i=0;i<splitTxts.length;i++){
TextView tv = new TextView(this);
ImageView img = new ImageView(this);
Log.v("Splited position", ""+i);
Log.v("Splited Text", splitTxts[i]);
tv.setText(splitTxts[i]);
if(selectedBook==3&&selectedSection==16){
img.setImageResource(arr204_16[i]);
}else if(selectedBook==8&&selectedSection==7){
img.setImageResource(arr209_8[i]);
}else if(selectedBook==8&&selectedSection==9){
img.setImageResource(arr209_10[i]);
}else if(selectedBook==8&&selectedSection==10){
img.setImageResource(arr209_11[i]);
}else if(selectedBook==8&&selectedSection==12){
img.setImageResource(arr209_13[i]);
}else if(selectedBook==8&&selectedSection==14){
img.setImageResource(arr209_15[i]);
}else if(selectedBook==16&&selectedSection==13){
img.setImageResource(arr217_14[i]);
}else if(selectedBook==19&&selectedSection==0){
img.setImageResource(arr220_1[i]);
}else if(selectedBook==19&&selectedSection==17){
img.setImageResource(arr220_18[i]);
}
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.gravity=Gravity.CENTER;
img.setLayoutParams(lp);
layout.addView(tv);
layout.addView(img);
}
}else
Log.v("Splited position", ""+selectedSection);
Log.v("Splited Text", text.split("@abc@")[selectedSection]);
view.setText(text.split("@abc@")[selectedSection]);
} catch (IOException e) {
// Should never happen!
Log.i("Exception", "true");
}
}
private static final int MENU_ABOUT = 1;
private static final int MENU_HELP = 2;
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_ABOUT, 0, "Bookmarks").setIcon(R.drawable.icon_abt1);
menu.add(0, MENU_HELP, 0, "Settings").setIcon(R.drawable.ckhelp);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ABOUT:
startActivity(new Intent(PageActivity.this, BookMarksActivity.class));
finish();
return true;
case MENU_HELP:
Intent intent = new Intent();
intent.setClass(PageActivity.this, YARPreferencesActivity.class);
startActivity(intent);
return true;
}
return false;
}
@Override
protected void onResume() {
super.onResume();
SharedPreferences pref =
}
I have done an app which will display the text from the assets folder, I used EditText
to show the text content. While testing my app text are displaying perfectly in HTC
wildfire whereas in Samsung ACE
, some of the text content are missing. I really don't know what might be the reason for this...
Can anyone help me to sort it out this issue please.
EDIT:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Intent extra = getIntent();
selectedBook = extra.getIntExtra("selectedbook", 0);
Log.v("selectedBook>>>>", ""+selectedBook);
selectedSection = extra.getIntExtra("selectedsection", 0);
Log.v("selectedSection>>>> ",""+ selectedSection );
contentTitle = extra.getStringExtra("contenttitle");
Log.v("contentTitle>>>> ",""+ contentTitle );
setContentView(R.layout.page);
layout = (LinearLayout)findViewById(R.id.layout);
view = (EditText) findViewById(R.id.text);
setTitleView();
setTextDisplay();
Spannable wordtoSpan = (Spannable) view.getText();
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
private void setTitleView() {
// TODO Auto-generated method stub
headingTitle = (TextView) findViewById(R.id.title_txt);
headingLbtn = (Button) findViewById(R.id.tbutton_left);
headingRbtn = (Button) findViewById(R.id.tbutton_right);
headingTitle.setText(contentTitle);
headingRbtn.setText("Bookmark");
headingLbtn.setText("Back");
headingLbtn.setVisibility(View.VISIBLE);
headingRbtn.setVisibility(View.VISIBLE);
headingLbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
headingRbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DbHelper db = new DbHelper(PageActivity.this);
db.addNote(selectedBook, selectedSection, contentTitle, "");
Toast.makeText(PageActivity.this, "Succesfully Bookmarked this section", Toast.LENGTH_SHORT).show();
}
});
}
private void setTextDisplay() {
try {
InputStream is = getAssets().open("" + selectedBook + ".txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
synchronized(this){
text = new String(buffer);
Log.v("WHOLETEXT",text);
Log.v("WHOLETEXT",""+text.length());
splitTxt = text.split("@abc@")[selectedSection];
}
String splitTxts[] = splitTxt.split("@xyz@");
Log.v("SPLITTEXT",""+splitTxts.length);
if(splitTxts.length!=1){
for(int i=0;i<splitTxts.length;i++){
TextView tv = new TextView(this);
ImageView img = new ImageView(this);
Log.v("Splited position", ""+i);
Log.v("Splited Text", splitTxts[i]);
tv.setText(splitTxts[i]);
if(selectedBook==3&&selectedSection==16){
img.setImageResource(arr204_16[i]);
}else if(selectedBook==8&&selectedSection==7){
img.setImageResource(arr209_8[i]);
}else if(selectedBook==8&&selectedSection==9){
img.setImageResource(arr209_10[i]);
}else if(selectedBook==8&&selectedSection==10){
img.setImageResource(arr209_11[i]);
}else if(selectedBook==8&&selectedSection==12){
img.setImageResource(arr209_13[i]);
}else if(selectedBook==8&&selectedSection==14){
img.setImageResource(arr209_15[i]);
}else if(selectedBook==16&&selectedSection==13){
img.setImageResource(arr217_14[i]);
}else if(selectedBook==19&&selectedSection==0){
img.setImageResource(arr220_1[i]);
}else if(selectedBook==19&&selectedSection==17){
img.setImageResource(arr220_18[i]);
}
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.gravity=Gravity.CENTER;
img.setLayoutParams(lp);
layout.addView(tv);
layout.addView(img);
}
}else
Log.v("Splited position", ""+selectedSection);
Log.v("Splited Text", text.split("@abc@")[selectedSection]);
view.setText(text.split("@abc@")[selectedSection]);
} catch (IOException e) {
// Should never happen!
Log.i("Exception", "true");
}
}
private static final int MENU_ABOUT = 1;
private static final int MENU_HELP = 2;
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_ABOUT, 0, "Bookmarks").setIcon(R.drawable.icon_abt1);
menu.add(0, MENU_HELP, 0, "Settings").setIcon(R.drawable.ckhelp);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ABOUT:
startActivity(new Intent(PageActivity.this, BookMarksActivity.class));
finish();
return true;
case MENU_HELP:
Intent intent = new Intent();
intent.setClass(PageActivity.this, YARPreferencesActivity.class);
startActivity(intent);
return true;
}
return false;
}
@Override
protected void onResume() {
super.onResume();
SharedPreferences pref =
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论