在XML定义编辑的TextView:机器人 [英] Android: edit textview defined in xml

查看:208
本文介绍了在XML定义编辑的TextView:机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经坐了至少4个小时试图解决这个问题。

I have been sitting for at least 4 hours trying to solve this problem.

要理解这个有3个文件,你需要了解:

To understand this there are 3 files you need to know about:

eggCatcher.java延伸活性,该类不用于比多
      游戏状态保存并显示optionsmenu。

eggCatcher.java which extends Activity, this class is not used for much more than saving gamestate and showing the optionsmenu.

eggCatcherView.java延伸SurfaceView,并包含游戏。

eggCatcherView.java which extends SurfaceView and contains "the game".

eggCatcher_layout.xml其如下所示:

eggCatcher_layout.xml which is shown below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/layouten">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <easter.fun.EggCatcherView
            android:id="@+id/eggcatcher"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <RelativeLayout android:id="@+id/relativeLayout1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true">

            <TextView android:text="Score: " 
                android:id="@+id/totalscore" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true">
             </TextView>

             <TextView android:text="Bonus: "
                android:id="@+id/bonus" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true">
        </TextView>

        </RelativeLayout>
    </FrameLayout>
</LinearLayout>

由于在XML文件中显示,EggCatcherView放在XML文件。
当应用程序我开始的onCreate调用的setContentView(layout.eggcatcher_layout);

As shown in the xml file, EggCatcherView is put in the xml file. When the applications i started the onCreate calls setContentView(layout.eggcatcher_layout);

我现在的问题是:
我怎样才能从EggCatcherView.java访问和编辑在XMLFILE定义的TextViews?

My question now is: how can i, from EggCatcherView.java access and edit the TextViews defined in the xmlfile?

如果有人在EggCatcher.java它会很容易,只需使用findViewById(id.bonus),但是从
里面的surfaceView似乎有点困难。

if it was in EggCatcher.java it would be easy, just use findViewById(id.bonus), but from inside the surfaceView appears to be a little more difficult.

我希望我所做的一切清楚,如果你不明白就问!

I hope i have made everything clear, if you dont understand just ask!

// micke

推荐答案

如果我理解正确的话,你要访问在周围活动的意见?这似乎是结构不良。我认为这将是更好的为pass回调到可以触发在活动的方法反过来对TextViews操作或火灾某种向上事件EggCatcherView。

If I understand correctly, you want to access the views in the surrounding activity? That seems like poor architecture. I think it would be better to either pass a callback to the EggCatcherView that can trigger methods in the Activity which in turn operate on the TextViews or fire some kind of events upwards.

这篇关于在XML定义编辑的TextView:机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆