Android TextView赢得';你不来吗?(安卓)

Android TextView赢得';你不来吗?(安卓),android,Android,尝试使用一个每次按下ImageButton都会增加1的整数,我在MainActivity中声明: int x = 0; //... private void configureImageButton() { ImageButton btn = (ImageButton) findViewById(R.id.imageButton1); btn.setOnClickListener(new View.OnClickListener() {

尝试使用一个每次按下ImageButton都会增加1的整数,我在MainActivity中声明:

int x = 0;
//...
private void configureImageButton() {
        ImageButton btn = (ImageButton) findViewById(R.id.imageButton1);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                TextView ed = (TextView) findViewById (R.id.textView1); 
                ed.setText (""+x++);
            }
        });
    }
在fragment_主xml文件中,我声明: (编辑以包括整个片段_主文件)



但我仍然没有在图形布局中显示textView1。我是Android新手,抱歉://

请发布您的完整布局文件-我猜它是相对的吗? 我已经给了你的布局一个快速的尝试-看起来一切都井然有序。你能试着为你的文本视图设置背景色吗

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageButton1"
    android:layout_centerHorizontal="true"
    android:ems="120" 
    android:background="#f00">


恐怕文本视图在那里,但你看不见

您的文本视图和图像视图位于图像按钮下方。如果希望文本视图位于ImageView下:

. . .
<ImageButton
    android:id="@+id/imageButton1"
    android:layout_above="@+id/imageView1"
    . . . />

<ImageView
    . . .
    android:id="@+id/imageView1"
    android:layout_below="@+id/imageButton1"
    android:layout_above="@+id/textView1" />

<TextView
    . . .
    android:id="@+id/textView1"
    android:layout_below="@+id/imageView1"
    android:layout_alignParentBottom="true">

    <requestFocus />
</TextView>

刚刚更新了原始帖子,你说得对:)我现在在图形布局上看到一条红线,但仍然没有显示0的x int的迹象。难道这也看不见吗?无论何时使用TextView,我都必须为text/int设置颜色吗?再次感谢你!:)我尝试了你所有的代码,没有发现任何问题。可能你可以尝试不同颜色的文字,然后看到?还是没有,尝试青色和黑色:/I我会尝试清理项目,然后从那里开始,也许尝试设置更大的文字大小?Idk…当然你应该尽你所能-我已经尝试了你的确切代码,它工作得很好。清理、重建、退出/重新启动eclipse。既然你原来的问题已经解决了,也许你可以把它标记为一个答案?只是一个更新,因为我仍然有x不显示的问题:我把图形布局旁边的值改为“x”,它显示字母x,所以显示int的东西不起作用。
. . .
<ImageButton
    android:id="@+id/imageButton1"
    android:layout_above="@+id/imageView1"
    . . . />

<ImageView
    . . .
    android:id="@+id/imageView1"
    android:layout_below="@+id/imageButton1"
    android:layout_above="@+id/textView1" />

<TextView
    . . .
    android:id="@+id/textView1"
    android:layout_below="@+id/imageView1"
    android:layout_alignParentBottom="true">

    <requestFocus />
</TextView>