我有一个应用程序,从启动屏幕开始,然后打开包含列表项的listactivity,点击任何一行将打开一个包含textview、两个按钮(其中一个打开无限画廊,另一个打开自定义对话框)和菜单项(关于、偏好、退出)的活动。
这个应用在Ginger Bread上运行得很完美,但当在运行Jelly Bean的Galaxy S3上测试时,它通常会打开,但当你点击listactivity中的某一行时,它似乎忽略了点击。在Eclipse的日志记录窗口中显示如下:
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
然而,没有强制关闭(列表活动正常滚动,菜单项也正常工作)。
更新:
我注意到了这个应用程序中的一些问题:大约一个月前,我使用eclipse创建了一个名为trip的应用程序,今天在ginger bread和jelly bean上测试trip.apk时它完美地工作。
但是我想把名称从trip更改为travel,我没有使用重构。相反,我创建了一个名为travel的新项目,但所有其他东西都与之前的应用程序trip相同,包括类、资源和在jelly bean上测试时显示的结果:
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
更新 3:
问题已解决:
我在我的应用程序的所有 TextView 中添加了这一行:
android:textIsSelectable="true"
该行导致点击被忽略,因此我将其删除后,旧版和新版应用程序都可以与API良好地配合使用。
更新4:
上述短语与旧问题有关并已解决。
现在的问题是:
我的应用程序在测试以下内容时可以与所有API完美配合使用:
运行jelly bean的Galaxy S3也可以完美运行,但在Eclipse日志记录中显示错误:
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
有没有任何想法可以解决这个错误,而不影响应用程序性能。
非常感谢您的任何解释和帮助,谢谢。
我的项目代码:
菜单:
public class Menu extends ListActivity {
String classes[] = { "Introduction", "DreamsTrip", "Day one", "Day Two",
"Day Three", "Day Four", "Day Five", "Conclusion" };
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
// create background for whole list as image
ListView lv = getListView();
lv.setCacheColorHint(0);
lv.setSelector(android.R.color.transparent);
lv.setPadding(30, 0, 30, 0);
lv.setVerticalScrollBarEnabled(false);
lv.setBackgroundResource(R.drawable.list_background);
lv.setDivider(new ColorDrawable(0x00000000));
setListAdapter(new MyArrayAdapter(this, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try {
Intent ourIntent;
if (position > 1 && position < 25) {
Class ourClass = Class.forName("com.test.demo.MyDay");
ourIntent = new Intent(Menu.this, ourClass);
ourIntent.putExtra("cheese", cheese);
} else {
Class ourClass = Class.forName("com.test.demo." + cheese);
ourIntent = new Intent(Menu.this, ourClass);
}
startActivity(ourIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public boolean onCreateOptionsMenu(android.view.Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.cool_menu, menu);
getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context,
AttributeSet attrs) {
if (name.equalsIgnoreCase(
"com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
view.setBackgroundResource(R.drawable.border3);
((TextView) view).setTextSize(25);
((TextView) view).setTypeface(FontFactory
.getBFantezy(getBaseContext()));
((TextView) view).setTextColor(Color.RED);
}
});
return view;
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.aboutUs:
Intent i = new Intent("com.test.demo.ABOUT");
startActivity(i);
break;
case R.id.preferences:
Intent p = new Intent("com.test.demo.PREFS");
startActivity(p);
break;
case R.id.exit:
finish();
break;
}
return false;
}
}
MyArrayAdapter:
public class MyArrayAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] classes;
Typeface tf;
static class ViewHolder {
public TextView text;
public ImageView image;
}
public MyArrayAdapter(Activity context, String[] classes) {
super(context, R.layout.row, classes);
this.context = context;
this.classes = classes;
tf = Typeface.createFromAsset(context.getAssets(), "BFantezy.ttf");
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.row, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.row_label);
viewHolder.image = (ImageView) rowView.findViewById(R.id.row_image);
viewHolder.text.setTypeface(FontFactory.getBFantezy(getContext()));
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
String s = classes[position];
holder.text.setText(s);
if (s.equals("Day one")) {
holder.image.setImageResource(R.drawable.day1);
}
if (s.equals("Day Two")) {
holder.image.setImageResource(R.drawable.day2);
}
if (s.equals("Day Three")) {
holder.image.setImageResource(R.drawable.day3);
}
if (s.equals("Day Four")) {
holder.image.setImageResource(R.drawable.day4);
}
if (s.equals("Day Five")) {
holder.image.setImageResource(R.drawable.day5);
}
if (s.equals("Conclusion")) {
holder.image.setImageResource(R.drawable.day_concl);
}
if (s.equals("DreamsTrip")) {
holder.image.setImageResource(R.drawable.day_trip);
}
if (s.equals("Introduction")) {
holder.image.setImageResource(R.drawable.day_intr);
}
return rowView;
}
}
我的一天:
public class MyDay extends Activity {
final Context context = this;
private Button button;
TextView tv2, tv3, tv4;
String day;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.day);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
}
initializeTextViews();
}
private void initializeTextViews() {
tv2 = (TextView) findViewById(R.id.day_tv1);
tv2.setTypeface(FontFactory.getBFantezy(getBaseContext()));
tv3 = (TextView) findViewById(R.id.day_tv3);
tv3.setTypeface(FontFactory.getDroidNaskh(getBaseContext()));
day = getIntent().getStringExtra("cheese");
if (day.equalsIgnoreCase("Day One")) {
tv2.setText(Html.fromHtml(getString(R.string.beginning)));
tv3.setText(Html.fromHtml(getString(R.string.day1)));
button = (Button) findViewById(R.id.city_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context,
R.style.cust_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog
.findViewById(R.id.dialog_text);
text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
text.setText(Html
.fromHtml(getString(R.string.torusim_places_1)));
Button dialogButton = (Button) dialog
.findViewById(R.id.dialog_Button);
dialogButton.setTypeface(FontFactory
.getBFantezy(getBaseContext()));
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
} else if (day.equalsIgnoreCase("Day Two")) {
tv2.setText(Html.fromHtml(getString(R.string.beginning)));
tv3.setText(Html.fromHtml(getString(R.string.day2)));
button = (Button) findViewById(R.id.city_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context,
R.style.cust_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog
.findViewById(R.id.dialog_text);
text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
text.setText(Html
.fromHtml(getString(R.string.torusim_places_2)));
Button dialogButton = (Button) dialog
.findViewById(R.id.dialog_Button);
dialogButton.setTypeface(FontFactory
.getBFantezy(getBaseContext()));
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
} else if (day.equalsIgnoreCase("Day Three")) {
tv2.setText(Html.fromHtml(getString(R.string.beginning)));
tv3.setText(Html.fromHtml(getString(R.string.day3)));
button = (Button) findViewById(R.id.city_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context,
R.style.cust_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog
.findViewById(R.id.dialog_text);
text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
text.setText(Html
.fromHtml(getString(R.string.torusim_places_3)));
Button dialogButton = (Button) dialog
.findViewById(R.id.dialog_Button);
dialogButton.setTypeface(FontFactory
.getBFantezy(getBaseContext()));
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
} else if (day.equalsIgnoreCase("Day Four")) {
tv2.setText(Html.fromHtml(getString(R.string.beginning)));
tv3.setText(Html.fromHtml(getString(R.string.day4)));
button = (Button) findViewById(R.id.city_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context,
R.style.cust_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog
.findViewById(R.id.dialog_text);
text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
text.setText(Html
.fromHtml(getString(R.string.torusim_places_4)));
Button dialogButton = (Button) dialog
.findViewById(R.id.dialog_Button);
dialogButton.setTypeface(FontFactory
.getBFantezy(getBaseContext()));
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
} else if (day.equalsIgnoreCase("Day Five")) {
tv2.setText(Html.fromHtml(getString(R.string.beginning)));
tv3.setText(Html.fromHtml(getString(R.string.day5)));
button = (Button) findViewById(R.id.city_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context,
R.style.cust_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog); // set the
// custom dialog components - text, image and button
TextView text = (TextView) dialog
.findViewById(R.id.dialog_text);
text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
text.setText(Html
.fromHtml(getString(R.string.torusim_places_5)));
Button dialogButton = (Button) dialog
.findViewById(R.id.dialog_Button);
dialogButton.setTypeface(FontFactory
.getBFantezy(getBaseContext()));
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
}
}
public void handleClick(View v) {
// Create an intent to start the new activity.
Intent intent = new Intent();
intent.setClass(this, DayGallery.class);
intent.putExtra("dayname", day);
startActivity(intent);
}
}
logcat:
D/AbsListView(14159): Get MotionRecognitionManager
D/dalvikvm(14159): GC_FOR_ALLOC freed 81K, 9% free 12164K/13315K, paused 13ms, total
13ms
I/dalvikvm-heap(14159): Grow heap (frag case) to 14.306MB for 1555216-byte allocation
D/dalvikvm(14159): GC_CONCURRENT freed 2K, 8% free 13681K/14855K, paused 12ms+1ms,
total 20ms
D/dalvikvm(14159): GC_FOR_ALLOC freed 0K, 8% free 13681K/14855K, paused 10ms, total
10ms
I/dalvikvm-heap(14159): Grow heap (frag case) to 16.941MB for 2764816-byte allocation
D/dalvikvm(14159): GC_CONCURRENT freed 0K, 7% free 16381K/17607K, paused 12ms+2ms,
total 23ms
D/libEGL(14159): loaded /system/lib/egl/libEGL_mali.so
D/libEGL(14159): loaded /system/lib/egl/libGLESv1_CM_mali.so
D/libEGL(14159): loaded /system/lib/egl/libGLESv2_mali.so
D/(14159): Device driver API match
D/(14159): Device driver API version: 10
D/(14159): User space API version: 10
D/(14159): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
D/OpenGLRenderer(14159): Enabling debug mode 0
D/dalvikvm(14159): GC_FOR_ALLOC freed 1732K, 16% free 15672K/18439K, paused 19ms,
total 19ms
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
D/dalvikvm(14159): GC_CONCURRENT freed 691K, 13% free 16102K/18439K, paused 13ms+2ms,
total 27ms
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
W/OpenGLRenderer(14159): Shape round rect too large to be rendered into a texture
(680x12472, max=4096x4096)
W/OpenGLRenderer(14159): Shape round rect too large to be rendered into a texture
(688x12480, max=4096x4096)
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero
length
LogCat
消息。 在Eclipse中,打开DDMS透视图并选择“LogCat”选项卡。 右侧是“Messages”部分,左侧是“Filters”部分。 选择“Filters”部分中的绿色加号。 在“Filter Name”中输入“MyApp”,在“by Application Name”字段中输入完整的包名称。 其余留空。 这将隔离来自您的应用程序的消息。 - mrres1onListItemClick
)。 您上面发布的那个方法不够用,因为您遇到问题的不是应用程序。 不要尝试在另一个程序中复制您的错误。 - mrres1