【发布时间】:2013-07-02 17:54:49
【问题描述】:
我的演示文稿终于奏效了。我的第一个屏幕有一个主activity,第二个屏幕有一个Presentation。
我的问题是,我无法更改演示视图中的内容。
为什么我不能在第二个屏幕上显示演示文稿后更改TextView?
在MainActivity 中调用changeText("Test123") 方法会使我的应用程序崩溃。
public class MainActivity extends Activity {
private PresentationActivity presentationActivity;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// init Presentation Class
DisplayManager displayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
if (presentationDisplays.length > 0) {
// If there is more than one suitable presentation display, then we could consider
// giving the user a choice. For this example, we simply choose the first display
// which is the one the system recommends as the preferred presentation display.
Display display = presentationDisplays[0];
PresentationActivity presentation = new PresentationActivity(this, display);
presentation.show();
this.presentationActivity = presentation;
}
}
public void changeText (String s) {
this.presentationActivity.setText(s);
}
}
public class PresentationActivity extends Presentation {
private TextView text;
private PresentationActivity presentation;
public PresentationActivity(Context outerContext, Display display) {
super(outerContext, display);
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_presentation);
TextView text = (TextView) findViewById(R.id.textView1);
this.text = text;
// works fine:
text.setText("test");
}
public void setText(String s){
// error
this.text.setText(s);
}
【问题讨论】:
-
使用 LogCat 检查与您的崩溃相关的 Java 堆栈跟踪。
-
嗨!我无法使用 LogCat,因为我的 USB 端口用于将第二个屏幕与 HDMI 连接。
-
edit:好的,有一些适用于 LogCat 的应用程序。我明天测试一下。谢谢!
-
然后在崩溃后断开 MHL(?) 电缆,将其插入开发机器上的 USB,然后然后检查 LogCat。或者,您可以让
adb通过 USB 工作,请参阅 tech.leolink.net/2012/11/use-adb-wifi-without-rooting-for.html。您引用的应用程序将无法运行,因为您无法在 Android 4.1+ 上的应用程序中查看来自其他进程的 LogCat 消息。
标签: android screen presentation